I don't understand how is this invalid syntax ? Can someone please explain it to me.

–1 vote
asked Feb 16 by anonymous

class Store():
 def __init__(self,name,id,price):
  self.name=name
  self.id=id
  self.price=price
  print("-----------")
 def discount(self,total):
  total=int(input("enter the total: ")
  if total<=3000
    discount=(0.25*total)
  elif total<=2000:
    discount =(0.15*total)
  elif total<=1000
    discount=0.10*total
  else:
    print("no discount for you")

item=Store(Chips, 10, 1000)
item=discount()

OUTPUT

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from solution import *
  File "/home/codewarrior/solution.py", line 10
    discount=(0.25*total)
           ^
SyntaxError: invalid syntax

4 Answers

0 votes
answered Feb 17 by anonymous
 
Best answer
# This corrects a few errors

class Store():
 def __init__(self,name,id,price):
     self.name=name
     self.id=id
     self.price=price
     print("-----------")
 def discount(self,total):
     total=int(input("enter the total: "))
     if total<=3000:
         discount=(0.25*total)
     elif total<=2000:
         discount =(0.15*total)
     elif total<=1000:
         discount=0.10*total
     else:
         print("no discount for you")

storeInstance = Store('Chips', 10, 1000)
item1 = storeInstance.discount(120)
commented Feb 18 by anonymous
Thank you so much. I have tried running this program but the discount function is not running, output only asks for total than the program stops.
0 votes
answered Feb 16 by anonymous
you forgot a semi colon for your if statement
commented Feb 17 by anonymous
Thank you for replying. I have tried putting the semi colon but it's still showing an error.
commented Feb 18 by Melodica_Covers (100 points)
you should do{

 if:
    #enter code
    pass
else:
+1 vote
answered Feb 17 by anonymous
if total<=3000: # NEVER FORGET COLON
0 votes
answered Apr 24 by michaelliu (140 points)
total=int(input("enter the total: ")
  if total<=3000
    discount=(0.25*total) # you loss ":" in your coding this line
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...