-6

I'm working with Python and I have nearly written some code as part of a required assignment.

#------Unit converter------#
#-------Challenge 5-------#
#-------Definitions-------#
def currencyConvert():
    print("C")

def tempConvert():
    print("T")

def massConvert():
    print("M")

def volConvert():
    print("V")

#-------Executions--------#
print("Welcome to my unit converter.\nIn this software, you can convert between the following things:")
print(" - Currency: United States Dollar (USD), Pound Sterling (GBP) and Serbian Dinar (RDS).")
print(" - Temperature: Fahrenheit (F) and Celsius (C)")
print(" - Mass: Pounds (lbs) and grams (mg/g/kg)")
print(" - Volume: Fluid ounces (fl oz) and litres (ml/cl/l")

def phaseOne():
    global unitType
    print("--------------------")
    unitType = input("What kind of conversion would you like to make? Currency (C), temperature (T), mass (M) or volume (V)?\n>>>")
    if unitType == "C" or "c":
        currencyConvert()
    elif unitType == "T" or "t":
        tempConvert()
    elif unitType == "M" or "m":
        massConvert()
    elif unitType == "V" or "v":
        volConvert()
    else:
        print("That is not a valid input. Please try again.")
        phaseOne()        

phaseOne()

My problem is that when I run the program and input "V", I would expect the volConvert() function to be called (therefore outputting "V") but instead it returns "C". What is causing this?

I do not have skills with Python yet, but I am working on it and need some minor help.

Thank you!

Adil B
  • 14,635
  • 11
  • 60
  • 78

1 Answers1

1

The conditions that you have work as (unitType == "C") or "c" and that is not what you want. Instead you want unittype in ("C", "c").

Martin Ueding
  • 8,245
  • 6
  • 46
  • 92