我得到了三个函数,命名为Aufgabe[1,2,3]。我想这样做,如果有人进入控制台“1”Aufgabe1
就会被触发,以此类推。有可能吗?你知道吗
AufgabenNummer = int(input("Welche Aufgabe willst du öffnen?\n"))
Aufgabe = "Aufgabe" + str(AufgabenNummer)
Aufgabe()
def Aufgabe1():
zahl1 = int(input("Erste Zahl...?\n"))
zahl2 = int(input("Zweite Zahl...?\n"))
print (str(zahl1) + "+" + str(zahl2) + "=" + str(zahl1+zahl2))
def Aufgabe2():
for i in range(0,11):
print(i)
def Aufgabe3():
name = int(input("Hallo wie heißt du?\n"))
print ("Hallo" + str(name))
最好的方法是维护名称/函数对字典:
然后通过在表中查找来调用相应的函数
这允许您更好地控制输入到函数的映射,从而允许您在不更改程序接口的情况下自由重构。你知道吗
相关问题 更多 >
编程相关推荐