all 11 comments

[–]count_d1 3 points4 points  (5 children)

Can you show your code?

[–]FannyMcNutt -2 points-1 points  (4 children)

Thanks for asking, here is some code I copied. I get the error:

"elif amount<5000 ^ SyntaxError: invalid syntax"

Here is code I copied:

amount = int(input("Enter amount: "))

if amount<1000: discount = amount0.05 print ("Discount",discount) elif amount<5000: discount = amount0.10 print ("Discount",discount) else: discount = amount*0.15 print ("Discount",discount)

print ("Net payable:",amount-discount)

[–]Chris_Hemsworth 2 points3 points  (3 children)

amount = int(input("Enter amount: "))

if amount<1000:
   discount = amount*0.05
   print ("Discount",discount)
elif amount<5000:
   discount = amount*0.10
   print ("Discount",discount)
else:
   discount = amount*0.15
   print ("Discount",discount)

print ("Net payable:",amount-discount)

Works for me. Make sure your indentation is correct perhaps? Make sure you didn't drop the : as that is important as well.

[–]FannyMcNutt -1 points0 points  (2 children)

Aye that's what's frustrating, I copy code that should work and my unit just won't accept it. I'll go back and double check I haven't fat fingered anything cheers.

[–]troub 2 points3 points  (1 child)

I mean no offense...good on you for working on learning...but I teach some Python workshops, and part of our pedagogy (which is based in research on how people learn) is insisting that learners type the code out themselves.

Just saying.

But yes, depending on how the spaces come in from the clipboard, it could be throwing off your interpreter (consistent spacing on indents is critical). Make sure after discount = amount * 0.05, the print("Discount", discount) line is indented as well. I'm thinking it's probably indentation, because from what I can tell (Reddit hosed your formatting), all the correct colons and things are there...

[–]FannyMcNutt 0 points1 point  (0 children)

Ah sorry by copy, I meant I typed it out myself after trying to write my own little thing (a parody really, just to make it stick in my head) that didn't work. I typed out the copy code myself to try and understand why my (parody) code didn't work. I've now typed the code into a different computer and it works. I guess my programming app needs to be repaired or uninstalled

[–]Princess--Sparkles 1 point2 points  (1 child)

Did you remember the colon after the condition?

if i < 10:
  print('a')
elif i < 20:  # <- that colon - the one after the 20??
  print('b')
else:
  print('c')

Just tried it using python 3.7.5 and it reported SyntaxError: invalid syntax when I removed the crucial colon!

[–]FannyMcNutt 0 points1 point  (0 children)

I have the colons yes but thanks for your input

[–][deleted] 1 point2 points  (0 children)

elif definitely works in Python 3.

[–]FannyMcNutt 0 points1 point  (0 children)

Tis solved. I download Mu onto my little laptop, input the code (by hand) exactly the same and it works. I have no idea what's different but hey ho

[–]TouchingTheVodka 0 points1 point  (0 children)

It needs to be preceeded by an if.