lundi 15 février 2021

Python 3 If statement not returning what's supposed to

I've recently started learning python and was experimenting with if statements and user inputs. My code was working fine, but now it's not (I may have changed something by accident, but I have no clue as to what it can be). No matter what I input, the console always returns the first if statement - the hours to seconds conversion. What's causing this?

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')

Aucun commentaire:

Enregistrer un commentaire