你在那里做什么:
def shoes():
j= "jordans"
a= "adidas"
n= "nikes"
question = input("whats ur fav. shoe?")
if a:
return a
只是命名-定义-发明了一个函数,该函数在脚本中的其他任何位置都调用(之后)为 shoes()。
当你想调用它时,你应该在某处显式调用它:shoes()
如果您希望您的 python 脚本定义一个函数,然后使用它,您应该编写:
# comments start of your script
#there I am defining the function shoes()
def shoes():
j= "jordans"
a= "adidas"
n= "nikes"
question = input("whats ur fav. shoe?")
if a:
return a
#there I'm calling right now the function shoes()
shoes() # there I do it inside the main script
你好像是新手,只是函数的另一个例子:
def unotherfunction(i):
for i in range(0,i+1):
shoes()
#If I call unotherfunction(), then, only then, shoes will be called twice, or fourth, or 7th or depending on the number your set to i like 2, 4 or 7..
unotherfunction(5) # will call 5 times your function shoes() ( asking you 5 times the same question of course ;-)
OPtionnally,也许你也应该添加一个测试,如:
question = input("whats ur fav. shoe?")
if a = question:
return a
这将使输入更有意义。否则,您通过键盘输入的内容根本不属于您的测试。
然后再次警告,你只有一个返回一个像样值的路径a...注意...你会看到...在其他路径中它会默默地返回None并给你惊喜...