Python Forum
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error in def
#1
Hello so in my program when I try to run it, it comes up with Syntax error then highlights my def statement (To help explain I underlined the part that is highlighted). I do not know why this is happening but I have tried retyping it with no success. How can I fix this error? If you want to know what it does then here it is: Pass_Cost() allows the user to pick their package and discount given from Pass_Package() and Pass_Discount(). If the user does not put in 7, 14 or 30 then the user is prompted to answer it correctly. Again the main problem is the Syntax error in def statement of Pass_Cost().

def Pass_Show():
print("Aussie Pass!")
print("Please select a package and discount depending on age.")
print("E.g. Package = 7")
Pass_Package()

def Pass_Package():
print("7 Day Pass – $139.95")
print("14 Day Pass - $239.95")
print("30 Day Pass - $500.00")
Pass_Discount()

def Pass_Discount():
print("Children (Under 15) - 60% off")
print("Students (Over 15 & less than 22) - 40% off")
print("Seniors (60 or over) - 50% off")
Pass_Cost()

def Pass_Total():
cost = Pass_Cost()
total = Pass_Calculate(cost)
print("The total cost is: $" + str(total)

def Pass_Cost():#User inputs the type of package they suit and discount
cost=list()
package = input("Package: ")
if package == "7" or "14" or "30": #If they enter those values they will move onto choosing their discount
print("Proceed...")
cost.append(package)
if package != "7" or "14" or "30":
Pass_Cost()#If they do not enter any of those values they will be prompted to ask again

discount = input("Discount: ")

if discount == "Children":
discount == 0.60
cost.append(discount)
if discount == "Students":
discount == 0.50
cost.append(discount)
if discount == "Seniors":
discount == 0.40
cost.append(discount)
if discount != "Children" or "Students" or "Seniors":
return discount


def Pass_Calculate(cost):
return cost[0] * cost[1] #Calculates the cost from their chosen package and discount e.g. 7 * 0.6
#7 being the chosen package (7 Day Pass) and 0.6 being Children discount




Pass_Show()
Reply
#2
The print statement at the end of Pass_Total is missing a close parentheses. Syntax errors are often on the line before where the error happens.

In the future please use BBCode to post programs (see the link in my signature below) and also post the full error message.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
I knew it was going to something simple as that thank you and I will use BBCode for posting programs
Reply
#4
You have another problem. A statement like:
if s != '7' or '14' or '30':
will not do what you expect, since '14' and '30' will be interpreted as True (not False, None or zero),
and the whole statement will always be true.

You should code:
if s not in ('7', '14', '30'):

Or more traditionally:

if s != '7' and s != '14' and s !='30:
Reply
#5
I was about to ask that, you read my mind!!! Thank you as well!!
Reply
#6
writing:
if s != '7' or '14' or '30':
is the same as
if s != '7':
because:
In [1]: '7' or '14' or '30'
Out[1]: '7'
Reply
#7
Is there a way to say this is answered? Sorry new to this site.
Reply
#8
The thread is not 'closed', but usually posts stop after the solution has been presented.
Reply
#9
You can edit the title of your thread to add a [Solved] tag, but no one ever does that.
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
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,306 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 1,994 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 1,999 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 1,966 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 3,409 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 3,133 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 4,034 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,235 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 2,427 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,068 Oct-19-2019, 01:40 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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