Advertisement
Guest User

unit converter

a guest
Feb 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.62 KB | None | 0 0
  1. print ("Welcome")#welcomes you to the program
  2. again = 0 #sets to 0 to start the program
  3. while again == 0:#loops the program at the end of asking the conversion
  4.  
  5.         cont = 0
  6.         while cont == 0:
  7.             measurement = input("Do you want to convert length or mass? ")
  8.             measurement = measurement.lower()
  9.             if measurement == "length" or measurement == "mass":
  10.                 cont = 1
  11.  
  12.         cont = 0
  13.         if measurement == "length":
  14.                 while cont == 0:
  15.                     length = input("Which unit do you want to convert? inch, foot, yard, or mile? ")
  16.                     length = length.lower()
  17.                     if length == "inch" or length == "foot" or length == "yard" or length == "mile":
  18.                         cont = 1
  19.  
  20.         cont = 0
  21.         if measurement == "mass":
  22.                 while cont == 0:
  23.                     mass = input("Which unit do you want to convert? gram, ounce, pound, or ton? ")
  24.                     mass = mass.lower()
  25.                     if mass == "gram" or mass == "ounce" or mass == "pound" or mass == "ton":
  26.                         cont = 1
  27. #start inches convert
  28.         cont = 0        
  29.         if length == "inch":
  30.             while cont == 0:
  31.                 try:
  32.                     amount = float(input("How many inches do you want to convert? "))
  33.                     if amount >= 0:
  34.                         print (amount, "inches converts into...")
  35.                         cont = 1
  36.                     elif amount < 0:
  37.                         print ("Positive numbers only")
  38.                 except:
  39.                     print ("Numbers only")
  40.             print ("\n")
  41.             print (amount / 12, "feet")
  42.             print (amount / 36, "yards")
  43.             print (amount / 63360, "miles")
  44.             print ("\n")
  45.            
  46.             cont = 0
  47.             while cont == 0:
  48.                 again = input("Do you want to restart? Yes or No ")
  49.                 again = again.lower()
  50.                 if again == "yes":
  51.                     cont = 1
  52.                     again = 0
  53.                 if again == "no":
  54.                     cont = 1
  55.                     print ("Goodbye")
  56.             print ("\n")
  57.        
  58.            
  59. #start foot convert
  60.         cont = 0        
  61.         if length == "foot":
  62.             while cont == 0:
  63.                 try:
  64.                     amount = float(input("How many feet do you want to convert? "))
  65.                     if amount >= 0:
  66.                         print (amount, "feet converts into...")
  67.                         cont = 1
  68.                     elif amount < 0:
  69.                         print ("Positive numbers only")
  70.                 except:
  71.                     print ("Numbers only")
  72.             print ("\n")
  73.             print (amount * 12, "inches")
  74.             print (amount / 3, "yards")
  75.             print (amount / 5280, "miles")
  76.             print ("\n")
  77.            
  78.             cont = 0
  79.             while cont == 0:
  80.                 again = input("Do you want to restart? Yes or No ")
  81.                 again = again.lower()
  82.                 if again == "yes":
  83.                     cont = 1
  84.                     again = 0
  85.                 if again == "no":
  86.                     cont = 1
  87.                     print ("Goodbye")
  88.             print ("\n")
  89.  
  90. #start yard convert
  91.         cont = 0        
  92.         if length == "yard":
  93.             while cont == 0:
  94.                 try:
  95.                     amount = float(input("How many yards do you want to convert? "))
  96.                     if amount >= 0:
  97.                         print (amount, "yards converts into...")
  98.                         cont = 1
  99.                     elif amount < 0:
  100.                         print ("Positive numbers only")
  101.                 except:
  102.                     print ("Numbers only")
  103.             print ("\n")
  104.             print (amount * 36, "inches")
  105.             print (amount * 3, "feet")
  106.             print (amount / 1760, "miles")
  107.             print ("\n")
  108.            
  109.             cont = 0
  110.             while cont == 0:
  111.                 again = input("Do you want to restart? Yes or No ")
  112.                 again = again.lower()
  113.                 if again == "yes":
  114.                     cont = 1
  115.                     again = 0
  116.                 if again == "no":
  117.                     cont = 1
  118.                     print ("Goodbye")
  119.             print ("\n")
  120.  
  121. #start mile convert
  122.         cont = 0        
  123.         if length == "mile":
  124.             while cont == 0:
  125.                 try:
  126.                     amount = float(input("How many miles do you want to convert? "))
  127.                     if amount >= 0:
  128.                         print (amount, "miles converts into...")
  129.                         cont = 1
  130.                     elif amount < 0:
  131.                         print ("Positive numbers only")
  132.                 except:
  133.                     print ("Numbers only")
  134.             print ("\n")
  135.             print (amount * 63360, "inches")
  136.             print (amount * 5280, "feet")
  137.             print (amount * 1760, "yards")
  138.             print ("\n")
  139.            
  140.             cont = 0
  141.             while cont == 0:
  142.                 again = input("Do you want to restart? Yes or No ")
  143.                 again = again.lower()
  144.                 if again == "yes":
  145.                     cont = 1
  146.                     again = 0
  147.                 if again == "no":
  148.                     cont = 1
  149.                     print ("Goodbye")
  150.             print ("\n")
  151.  
  152. #start grams convert
  153.         cont = 0
  154.         if mass == "gram":
  155.             while cont == 0:
  156.                 try:
  157.                     amount = float(input("How many miles do you want to convert? "))
  158.                     if amount >= 0:
  159.                         print (amount, "miles converts into...")
  160.                         cont = 1
  161.                     elif amount < 0:
  162.                         print ("Positive numbers only")
  163.                 except:
  164.                     print ("Numbers only")
  165.             print ("\n")
  166.             print (amount * 63360, "inches")
  167.             print (amount * 5280, "feet")
  168.             print (amount * 1760, "yards")
  169.             print ("\n")    
  170.            
  171.             cont = 0
  172.             while cont == 0:
  173.                 again = input("Do you want to restart? Yes or No ")
  174.                 again = again.lower()
  175.                 if again == "yes":
  176.                     cont = 1
  177.                     again = 0
  178.                 if again == "no":
  179.                     cont = 1
  180.                     print ("Goodbye")
  181.             print ("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement