Click here to Skip to main content
14,484,894 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I have to do this for my assignment but I need help!. I have tried entering the letter I but it doesn't work please tell me what am doing wrong or didn't do cant seem to figure it out.
This program will convert distances (Inches/Miles)
Ehter (I) to convert Inches to miles
Enter (M) to convert Miles to Inches
Enter selection: I
Enter distance to convert: 115
115.0 Inches equals 0.00181502 Miles. then

This program will convert distances (inches/miles)
enter (I) to convert to Miles
enter (M) to convert miles to inches
enter selection: N
Please enter 'I' or 'M': R

What I have tried:

this is all I have done
tterinteger = I
d_ft = int(input("Enter (I) to convert Inches to Miles: "))

d_miles = d_ft / 5280.0
d_yards = d_ft / 3.0


print("The distance in inches is %i inches." % d_inches)
print("The distance in yards is %.2f yards." % d_yards)
print("The distance in miles is %.2f miles." % d_miles)
12345678
Posted
Updated 31-Oct-18 10:50am
Rate this:
Please Sign up or sign in to vote.

Solution 1

You are asking for an input in inches, and treating it as if it was in feet...
Try this:
d_inches = int(input("Enter Inches to convert: "))
d_ft = d_inches / 12.0
d_miles = d_ft / 5280.0
d_yards = d_ft / 3.0


print("The distance in inches is %i inches." % d_inches)
print("The distance in feet is %.1f feet." % d_ft)
print("The distance in yards is %.2f yards." % d_yards)
print("The distance in miles is %.6f miles." % d_miles)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Here is the multiplication table set for conversions. Repeating decimals are signified by a - at the end of the decimal
inch	feet	  yard    mile
_____  ________   _______  ___________
1	    0.0833-	  0.0277-  0.000015782
12	    1	      0.33-	   0.000189394
36	    3	      1	       0.0005681-
63360	5280	  1760	   1
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100