Python Forum
Can u see this code and tell whats wrong with it? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can u see this code and tell whats wrong with it? (/thread-26329.html)

Pages: 1 2


Can u see this code and tell whats wrong with it? - AhmadKamal - Apr-28-2020

### 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}")



RE: Can u see this code and tell whats wrong with it? - buran - Apr-28-2020

https://python-forum.io/Thread-Multiple-expressions-with-or-keyword

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


RE: Can u see this code and tell whats wrong with it? - Yoriz - Apr-28-2020

Possibly this
Multiple expressions with "or" keyword
also
if unit == "months" or m :
"" missing from m


RE: Can u see this code and tell whats wrong with it? - AhmadKamal - Apr-28-2020

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-expressions-with-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



RE: Can u see this code and tell whats wrong with it? - jefsummers - Apr-28-2020

That is because of mismatched parentheses on the line before. 4 opens and only 3 close


RE: Can u see this code and tell whats wrong with it? - AhmadKamal - Apr-28-2020

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



RE: Can u see this code and tell whats wrong with it? - deanhystad - Apr-28-2020

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.


RE: Can u see this code and tell whats wrong with it? - buran - Apr-28-2020

also on line 7:
age = int((input("How old Are u? ")).strip()
check the number of opening and closing brackets and fix it accordingly


RE: Can u see this code and tell whats wrong with it? - AhmadKamal - Apr-28-2020

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}")



RE: Can u see this code and tell whats wrong with it? - Yoriz - Apr-28-2020

You didn't fix the or statement, the first if will always be True.
You didn't fix the multiplication of a string.