【发布时间】:2021-02-15 18:06:41
【问题描述】:
我最近开始学习 python 并尝试使用 if 语句和用户输入。我的代码工作正常,但现在不行(我可能不小心改变了一些东西,但我不知道它可能是什么)。无论我输入什么,控制台总是返回第一个 if 语句——小时到秒的转换。这是什么原因造成的?
print('Welcome to the time to seconds converter')
option = input('Please choose what you want to convert ')
if option == 'hours' or 'Hours':
hours = int(input('How many hours to seconds would you like to convert? '))
product1 = (hours * 60) * 60
print(hours, 'hours are', product1, 'seconds')
elif option == 'minutes' or 'Minutes':
minutes = int(input('Please choose how many minutes to seconds you would like to convert '))
product2 = minutes * 60
print(minutes, 'minutes are', product2, 'seconds')
elif option == 'days' or 'Days':
days = int(input('How many days would you like to convert to seconds? '))
product3 = ((days * 24) * 60) * 60
print(product3)
elif option == 'years' or 'Years':
years = int(input('How many years would you like to convert in to seconds? '))
product4 = (((years * 365) * 24) * 60) * 60
print(product4)
else:
print('Sorry, I do not recognize that')
【问题讨论】:
标签: python-3.x if-statement input