This question already has an answer here:
started coding in Python very recently and extremely fresh.
I'm trying to create a miles to km or km to miles converter.
The conversion part works and returns the value after the user inputs it.
choice = raw_input("Press 1 to convert Miles to KM or 2 for KM to Miles: ")
valid = ("1" or "2")
while choice in valid:
if choice == "1":
milesInput = float(raw_input("Enter the amount of miles:\n"))
print ("The total KM is: ")
print milesInput * 1.609
elif choice == "2":
kmInput = float(raw_input("Enter the amount of kilometres: \n"))
print ("The total miles is: ")
print kmInput * 0.621
If i enter the choice as "2" - it just finishes the code despite the condition being true.
Any advice is greatly appreciated. What am i doing wrong?
Aucun commentaire:
Enregistrer un commentaire