Python Forum
Can u see this code and tell whats wrong with it?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can u see this code and tell whats wrong with it?
#1
### 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}")
Reply
#2
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

Reply
#3
Possibly this
Multiple expressions with "or" keyword
also
if unit == "months" or m :
"" missing from m
Reply
#4
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
Reply
#5
That is because of mismatched parentheses on the line before. 4 opens and only 3 close
Reply
#6
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
Reply
#7
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.
Reply
#8
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

Reply
#9
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}")
Reply
#10
You didn't fix the or statement, the first if will always be True.
You didn't fix the multiplication of a string.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 476 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Something wrong with my code FabianPruitt 5 847 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,554 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,248 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,779 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,535 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Wrong code in Python exercise MaartenRo 2 1,526 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,627 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  VS Code debugger using wrong Python environment topfox 0 2,496 Jun-09-2021, 10:01 AM
Last Post: topfox
  Whats wrong with the elif? inunanimous93 3 2,446 Nov-30-2020, 03:58 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020