satya

Wednesday, October 7, 2020

Program 16

                                                                                 Program 16

Write a program that asks the user to enter a length in feet. The program should then give the user the option to convert from feet into inches, yards, miles, millimeters, centimeters, meters, or kilometers. Say if the user enters a 1, then the program converts to inches, if they enter a 2, then the program converts to yards, etc. While this can be done with if statements,it is much shorter with lists and it is also easier to add new conversions if you use lists.


feet=int(input("Enter the Length in  Feet:"))

print("""Choose 1 to convert into inches,

choose 2 to convert into yards,

choose 3 to convert into miles,

choose 4 to convert into millimeters,

choose 5 to convert into centimeters,

choose 6 to convert into meters,

choose 7 to convert into kilometers""")


opt=int(input('Enter the your  choice:'))

              

if(opt==1):

    print("Inches is:",feet * 12)

elif(opt==2):

    print("Yards is:",feet * 0.33333)

elif(opt==3):

    print("Miles is:",feet * 0.000189393939)

elif(opt==4):

    print("MilliMeters is:",feet * 304.8)

elif(opt==5):

    print("centimeters is:",feet * 30.48)

elif(opt==6):

    print("meters is:",feet * 0.3048)

elif(opt==7):

    print("kilometersis:",feet * 0.0003048)

OUTPUT:

>>> 

===== RESTART: D:/old/r19 lab-python/16.py ==============

Enter the Length in  Feet:6

Choose 1 to convert into inches,

choose 2 to convert into yards,

choose 3 to convert into miles,

choose 4 to convert into millimeters,

choose 5 to convert into centimeters,

choose 6 to convert into meters,

choose 7 to convert into kilometers

Enter the your choice:1

Inches is: 72

>>> 

========== RESTART: D:/old/r19 lab-python/16.py ==========

Enter the Length in  Feet:6

Choose 1 to convert into inches,

choose 2 to convert into yards,

choose 3 to convert into miles,

choose 4 to convert into millimeters,

choose 5 to convert into centimeters,

choose 6 to convert into meters,

choose 7 to convert into kilometers

Enter the your  choice:2

Yards is: 1.99998

No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...