Python Forum

Full Version: Need help with "unexpected expression syntax error"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone!
I'm new to python and was hoping to get some help with the code below.
I've worked out that the error pops up whenever I try to finish the second 'if, else' statement.
I am not sure how to fix it though, and some help would be greatly appreciated.

def coin_flip(coinbet, h_or_t):
  flip = 0
  if (h_or_t == "H"):
    guess = heads
  elif (h_or_t == "T"):
    guess = tails
  else:
    print("Please write in correct format")
  flip = random.randit(1, 2)
  if (flip == 2) and (guess == tails):
    print("You flipped tails! Nice job!")
    print("You won " + str(coinbet*2) + "!")
  elif (flip == 1) and (guess == heads):
    print("You flipped heads! Nice job!")
    print("You won " + str(coinbet*2) + "!"
  else:
    print("test")
File "script.py", line 22
    else:
       ^
SyntaxError: invalid syntax
you have missing closing bracket on line 15
(Sep-29-2019, 05:28 AM)buran Wrote: [ -> ]you have missing closing bracket on line 15

Thanks!!! That's so obvious, can't believe I spent so long trying to find a fix!