-3

Here is my code:

#Starting Point
import time
print("This calculator will convert measurements into a unit of choice")
time.sleep(2)
print("Here are the choice:")
time.sleep(0.5)
print("")
print(" Centimetres, Metres, Kilometres")
time.sleep(0.5)
print("")
print(" Seconds, Minutes, Hours")
time.sleep(0.5)
print("")
print(" Millilitres, litres")
time.sleep(0.5)
print("")
print(" Grams, Kilograms")
time.sleep(0.5)
print("")
#question on convertion
answer = input("Which unit of measurement would you like to use(please enter    L for length T for time V for volume and C for capacity?")


 #program for length
 if answer == "L":
  length = input("What  unit do you want to convert?( C for centimetres M for                      Metres and K for kilometres)")
  print()
 if length  == "C":
    convert_l_1 = input("What do you want to convert centimetres into?(M for    metres and K for Kilometres)")
 elif length == "M":
    convert_l_2 = input("What do you want to convert metres into?( C for    centimetres and K for kilometres)")
 elif length == "K":
    convert_l_3 = input("What do you want to convert Kilometres into?(C for    centimetres and M for metres)")



  #program for Time
   elif answer == "T":
    time = input("What unit do you want to convert?( S for seconds M for    minutes and H for hours)")
     print()
   if time == "S":
     convert_t_1 = ("What do you want to convert seconds into?(M for minutes and   H for hours)")
   elif time == "M":
     convert_t_2 = ("What do you want to convert Minutes to?(S for seconds and H for hours)")
   elif time == "H":
       convert_t_3 = ("What do you want to convert hours to?(S for seconds and M for minutes)")



#program for volume
elif answer == "V":
 volume = input("What unit do you want to convert?(M for millilitres and L for litres)")
print()
if volume == "M":
 convert_v_1 = input("Do you want to convert millilitres to litres?(Y for yes and N for no")
elif volume == "L":
 convert_v_2 = input("Do you want to convert litres to millilitres?(Y for yes and N for no")




#program for capacity
elif answer == "C":
 capacity = input("What unit do you want to convert?( G for grams and K for Kilograms)")
Mykola
  • 3,343
  • 6
  • 23
  • 39

3 Answers3

0

Your problem is here:

if answer == "L":
    length = input("What  unit do you want to convert?( C for centimetres M       for                      Metres and K for kilometres)")
    print()

if length  == "C":

If answer is not 'L', then length will never be defined because you don't assign it anywhere else. Note this could merely be an indentation issue. Make sure the "if length..." statements are indented inwards from the check that answer=="L" if that is your intent.

jeff carey
  • 2,313
  • 3
  • 13
  • 17
0

The problem is with your current indentation. http://www.codeskulptor.org/#user40_pcJ0kOCzXI_0.py

The wrong indentation leads to the variable length never being defined and creating an error.

I would advise you to take a look at the PEP 8 -- Style Guide for Python Code: http://legacy.python.org/dev/peps/pep-0008/#indentation

#program for length
if answer == "L":
    length = input("What  unit do you want to convert?( C for centimetres M for                      Metres and K for kilometres)")
    print()
    if length  == "C":
        convert_l_1 = input("What do you want to convert centimetres into?(M for    metres and K for Kilometres)")
    elif length == "M":
        convert_l_2 = input("What do you want to convert metres into?( C for    centimetres and K for kilometres)")
    elif length == "K":
        convert_l_3 = input("What do you want to convert Kilometres into?(C for    centimetres and M for metres)")
Ryan
  • 2,167
  • 2
  • 28
  • 33
0

notice the indenting, and the input statements you forgot, also added upper() so people can enter either upper or lower case responses

#question on convertion
answer = input("Which unit of measurement would you like to use(please enter L for length T for time V for volume and C for capacity?").upper()


#program for length
if answer == "L":
    length = input("What  unit do you want to convert?( C for centimetres M for Metres and K for kilometres)").upper()
    if length  == "C":
        convert_l_1 = input("What do you want to convert centimetres into?(M for metres and K for Kilometres)").upper()
    elif length == "M":
        convert_l_2 = input("What do you want to convert metres into?( C for centimetres and K for kilometres)").upper()
    elif length == "K":
        convert_l_3 = input("What do you want to convert Kilometres into?(C for centimetres and M for metres)").upper()

#program for Time
elif answer == "T":
    time = input("What unit do you want to convert?( S for seconds M for minutes and H for hours)").upper()
    if time == "S":
        convert_t_1 = input("What do you want to convert seconds into?(M for minutes and H for hours)").upper()
    elif time == "M":
        convert_t_2 = input("What do you want to convert Minutes to?(S for seconds and H for hours)").upper()
    elif time == "H":
        convert_t_3 = input("What do you want to convert hours to?(S for seconds and M for minutes)").upper()

#program for volume
elif answer == "V":
    volume = input("What unit do you want to convert?(M for millilitres and L for litres)").upper()
gkusner
  • 1,244
  • 1
  • 11
  • 14