1

I'm new to python coding and I am working on a simple program that converts your years to months, minutes, and seconds. However, when I ask to convert the years to just one of those it responds by sending me the answer to all of the conversions. Can someone look over this and tell me what I did wrong?

Year = int(input("Years: "))
unit = input("Months or Minutes or Seconds: ")
if unit == "Months" or "months":
    convert = Year * 12
    print(str(convert)) 
if unit == "Minutes" or "minutes":
    convert1 = Year * 525600
    print(str(convert1))
if unit == "Seconds" or "second":
    convert2 = Year * 31536000
    print(str(convert2))
  • 1
    While the duplicate answers the "why", I'd simplify your existing checks to just: `if unit.lower() == "months":`, for example. Just standardize `unit` before doing the check. Read the dupe though, as this is an important (common) mistake to understand the cause behind. – Carcigenicate Nov 18 '22 at 23:42
  • RIght. There are two good choices: using `.lower` as above, or saying `unit in ('Months','months')`. – Tim Roberts Nov 18 '22 at 23:42

0 Answers0