code
Python exercise: Write Miles to Km Converter
Python exercise
*************
Episode: 5
Level: Beginner
Single Mile is approximately 1.609 Kilometres. Write Python function which gets input from user and converters given Miles to Km. You should also check if number is greater than zero. If not, ask user for another input. If number is positive display it in Km.
If string is entered function is called again to display input once more.
If negative value is entered function is called again.
Solution:
def converter():
''' Write function which converts Miles to Km '''
print("Enter number in Miles: ")
a = input()
try:
a = float(a)
if a > 0:
print(str(a * 1.609) + " Km.")
else:
converter()
except:
converter()
converter()
How would create tkinter UI for converter? This will be next post subject.
o_o

Post a Comment
0 Comments
Thanks for sharing your thoughts !