### 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}") Can u see this code and tell whats wrong with it?
| Can u see this code and tell whats wrong with it? |
| Apr-28-2020, 04:49 PM https://python-forum.io/Thread-Multiple-...or-keyword in addition on line 7 m is missing quotes and will raise NameError If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs Apr-28-2020, 04:50 PM Possibly this Multiple expressions with "or" keyword also if unit == "months" or m :"" missing from m Apr-28-2020, 05:32 PM 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 (Apr-28-2020, 04:50 PM)Yoriz Wrote: Possibly this Apr-28-2020, 05:39 PM That is because of mismatched parentheses on the line before. 4 opens and only 3 close Apr-28-2020, 05:48 PM 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 Apr-28-2020, 06:01 PM 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. Apr-28-2020, 06:07 PM also on line 7: age = int((input("How old Are u? ")).strip()check the number of opening and closing brackets and fix it accordingly If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs Apr-28-2020, 08:52 PM (This post was last modified: Apr-28-2020, 08:52 PM by AhmadKamal.) 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. |
| |
Users browsing this thread: 1 Guest(s)
