Python Forum
What is wrong with my code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is wrong with my code?
#1
Hi, why am I getting an invalid syntax error for "student = True"? This code was already initialize for me in the assignment, and when I went to go use it I get a syntax error. Any help or feedback would be greatly appreciated it!

plan = 'M' # ‘M’ = monthly, ‘D’ = daily
hours = 35
student = True
senior = False
total = 0

# write the code to calculate the total below
base = 30
hourfee = 3
discount = 0.10

 if hours > 30:
  if student = True:
   total hour fee = (hours - 30)*hourfee
   total fee = (total hour fee + base)*discount
  
  elseif: student = False:
   total hour fee = (hours - 30)*hourfee
   total fee = total hour fee + base

print(total fee) 
Reply
#2
For equality testing, Python uses two equals signs. So line 12 should be if student == True:. However, you should test to see if something is equal to true. Just test the object directly: if student:.

You'll get another syntax error on line 17. 'elseif' is not Python, Python uses 'elif'. And any condition should be before the colon, as in elif student == False:. But again, you don't check equality to False. You could do elif not student:, but since student is either going to be True or False, it should really just be else:.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  im not sure what ive done wrong code doesnt run dgizzly 3 1,334 Nov-16-2022, 03:02 AM
Last Post: deanhystad
  what is wrong with my code 53535 4 1,487 Apr-07-2022, 11:37 AM
Last Post: 53535
  What's wrong with my code? NeedHelpPython 4 2,152 Oct-22-2021, 07:59 PM
Last Post: Yoriz
  Help with my code due 11:59 pm, can you tell me where I went wrong and help fix it? shirleylam852 1 2,609 Dec-09-2020, 06:37 AM
Last Post: stranac
  I am getting an incorrect average, and not sure why? What's wrong with my code? shirleylam852 8 4,594 Nov-20-2020, 05:32 AM
Last Post: deanhystad
  Something is Wrong with my code susmith552 4 2,984 Nov-28-2019, 02:16 AM
Last Post: susmith552
  Wrong output on my code. JTNA 2 7,852 Apr-04-2019, 01:55 PM
Last Post: JTNA
  Why is this code wrong? Lemmy 4 5,134 Apr-05-2018, 03:46 PM
Last Post: Lemmy
  What's wrong with my code and visuals for python? beginnercoder04 2 2,768 Mar-17-2018, 01:06 AM
Last Post: beginnercoder04
  whats wrong with my code? syntax errors r6lay 5 6,404 Mar-16-2017, 04:14 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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