Python Forum
Thanks in advance for your help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thanks in advance for your help
#1
Sad 
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
Reply
#2
show what you think the code should be. Then ask specific question about problem area.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code by Voice using Python ( Need HELP in making ADVANCE ) pawandeore 0 1,430 Feb-24-2021, 06:59 PM
Last Post: pawandeore

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020