programming need help with python program
Go to solution
Solved by LtStaffel,
Here is a python 2.7 version of your script (because I'm using PyPy which is 2.7 style syntax)
Please mark this post as the answer so the thread is "solved"
Spoiler
from random import * def answer(): # You don't need elif, it either will be 1 or zero so only make one check and use else x = (randint(0, 1)) if x == 1: return "HEADS" else: return "TAILS" # You were returning the parameter given to the function, when the function didn't need a parameter # You were also printing the result instead of returning it playerChoice = str(raw_input("Heads or Tails: ")).upper() if playerChoice == 'HEADS' or 'TAILS': # You didn't indent properly print "You chose: " + playerChoice # You don't need to wait a split second # Also, the computer doesn't get a choice if the player chooses # Here we get the result using your function "answer" ans = answer() print "You chose ::: " + playerChoice print "The answer ::: " + ans if playerChoice == ans: print "You won!" else: print "You lost!" else: print "Invalid input!"
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now