Python Forum

Full Version: Can u see this code and tell whats wrong with it?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
### Age Advanced TEST ##
months = age * 12
weeks = months * 4
days = age - 365
unit = input("Choose you Format age (Months, Days, Weeks}").strip().lower()
age = int((input("How old Are u? ")).strip()
if unit == "months" or m :
    print(f"{months}")
elif unit == "weeks" or "w" :
    print(f"{weeks}")
elif unit == "days" or "d" :
    print(f"{days}")
https://python-forum.io/Thread-Multiple-...or-keyword

in addition on line 7 m is missing quotes and will raise NameError
Possibly this
Multiple expressions with "or" keyword
also
if unit == "months" or m :
"" missing from m
Visual Srudio Code told me
if unit == "months" or "m":
^
SyntaxError: invalid syntax

and i edited it and still error


(Apr-28-2020, 04:49 PM)buran Wrote: [ -> ]https://python-forum.io/Thread-Multiple-...or-keyword

in addition on line 7 m is missing quotes and will raise NameError

(Apr-28-2020, 04:50 PM)Yoriz Wrote: [ -> ]Possibly this
Multiple expressions with "or" keyword
also
if unit == "months" or m :
"" missing from m
That is because of mismatched parentheses on the line before. 4 opens and only 3 close
sry i didnt get it here's the whole code:

### Age Advanced TEST ##
months = age * 12
weeks = months * 4
days = age - 365

unit = input("Choose you Format age (Months, Days, Weeks}").strip().lower()
age = int((input("How old Are u? ")).strip()

if unit == "months" or "m":
    print(f"{months}")
elif unit == "weeks" or "w":
    print(f"{weeks}")
elif unit == "days" or "d":
    print(f"{days}")
(Apr-28-2020, 05:39 PM)jefsummers Wrote: [ -> ]That is because of mismatched parentheses on the line before. 4 opens and only 3 close
I suggest you insert this in your code just above the if/elif statement:

print(unit == "months" or "m")

I don't think it is going to print True or False.
also on line 7:
age = int((input("How old Are u? ")).strip()
check the number of opening and closing brackets and fix it accordingly
I Solved it thanks a lot

### Age Advanced TEST ##
unit = input("Choose you Format age (Months, Days, Weeks}").strip().lower()
age = input("How old Are u? ")

months = age * 12
weeks = months * 4
days = age * 365

if unit == "months" or "m":
    print(f"{months}")
elif unit == "weeks" or "w":
    print(f"{weeks}")
elif unit == "days" or "d":
    print(f"{days}")
You didn't fix the or statement, the first if will always be True.
You didn't fix the multiplication of a string.
Pages: 1 2