Python Forum

Full Version: Thanks in advance for your help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
kilometres = int(input("Enter value in kilometres: "))
conv_fac = 0.6214
miles = kilometres * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometres,miles))
You will add several new tests to your program:

Modify your program such that it verify that the user has entered a positive distance (i.e. they cannot enter a negative number).

Now modify your program to verify that the input is a number; if it is not a number then do nothing; otherwise convert the distance to miles.

To check to see if a string contains only digits use the method isnumeric() for example '42'.isnumeric(); which returns True if the string only contains numbers. Note this method only works for positive integers; but this is sufficient for this question.

I couldn't add what I needed to add please help Shy
show what you think the code should be. Then ask specific question about problem area.