【发布时间】:2017-10-17 05:46:33
【问题描述】:
例如,当我在此函数中添加以下多个返回时,我正在为学校编写的代码给了我一个元组错误
def GetHowLongToRun():
print('Welcome to the Plant Growing Simulation')
print()
print('You can step through the simulation a year at a time')
print('or run the simulation for 0 to 5 years')
print('How many years do you want the simulation to run?')
Years = int(input('Enter a number of years to run, or -1 for stepping mode:'))
skipyear = input("Would you like to pause every year? Y/N")
skipseason = input("Would you like to pause every season? Y/N")
return Years, skipyear, skipseason
这给了我以下错误
Traceback (most recent call last):
File "C:\Users\jonwe\Downloads\Paper1_ASLv1_2017_Python3_Pre (1).py", line 170, in <module>
Simulation()
File "C:\Users\jonwe\Downloads\Paper1_ASLv1_2017_Python3_Pre (1).py", line 154, in Simulation
if YearsToRun >= 1:
TypeError: '>=' not supported between instances of 'tuple' and 'int'
但如果我只返回“Years”字符串,它不会给我任何错误并且可以完美运行
【问题讨论】:
标签: python-3.x function return tuples