#poloh
import random
userHand = input("rock, paper, or scissors")
computerHand = random.random()
if computerHand < .33:
computerHand = ("rock")
elif computerHand < .66:
computerHand = ("paper")
else:
computerHand = ("scissors")
def game(first,second):
if first == second:
print ("You chose",first)
print ("Computer chose", second)
print ("It's a tie!")
elif first == ("rock"):
if second == ("scissors"):
print ("You chose",first)
print ("Computer chose",second)
print ("You Win!")
else:
print ("You chose", first)
print ("Comuter chose", second)
print ("You lose.")
elif first == ("paper"):
if second == ("rock"):
print ("You chose",first)
print ("Computer chose",second)
print ("You Win!")
else:
print ("You chose", first)
print ("Comuter chose", second)
print ("You lose.")
elif first == ("scissors"):
if second == ("paper"):
print ("You chose",first)
print ("Computer chose",second)
print ("You Win!")
else:
print ("You chose", first)
print ("Comuter chose", second)
print ("You lose.")
game(userHand,computerHand)
Indented for easier reading.Code:#poloh import random userHand = input("rock, paper, or scissors") computerHand = random.random() if computerHand < .33: computerHand = ("rock") elif computerHand < .66: computerHand = ("paper") else: computerHand = ("scissors") def game(first,second): if first == second: print ("You chose",first) print ("Computer chose", second) print ("It's a tie!") elif first == ("rock"): if second == ("scissors"): print ("You chose",first) print ("Computer chose",second) print ("You Win!") else: print ("You chose", first) print ("Comuter chose", second) print ("You lose.") elif first == ("paper"): if second == ("rock"): print ("You chose",first) print ("Computer chose",second) print ("You Win!") else: print ("You chose", first) print ("Comuter chose", second) print ("You lose.") elif first == ("scissors"): if second == ("paper"): print ("You chose",first) print ("Computer chose",second) print ("You Win!") else: print ("You chose", first) print ("Comuter chose", second) print ("You lose.") game(userHand,computerHand)
Also, if you want to print on a new line, instead of doing three print statements, there should be some way to use a newline to put it all into one statement, idk how though.
Plus, since you're printing the users choice, and computers choice every time, you can print it above the if statements to remove a lot of repetition from your code.
if you care about using the newline over multiple print statements.Code:print("You chose", first, "\nComputer chose", second)
Last edited by Nimboso; 01-11-2017 at 07:48 PM.