I am trying to play rock paper scissors against a computer from a file. I keep getting the else from my check win function. It should be a different outcome depending on what random number the computer gets. Can someone please help?
this is the name.text file. Gary - rock Frederico - scissors Amalie - paper Bill - scissors Billy Bob - paper End
#import random module
import random
#function for checking input.
def check_input():
#open name file txt
name_file = open("names.txt", "r")
#for loop to separate name and token
for name in name_file.readlines():
name_number = name.find("-")
name_slice = name[:name_number]
token = name[name_number + 1:]
if token == "End":
break
comp_choice = random.randint(1, 3)
while comp_choice < 4:
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice = "rock"
elif comp_choice == 2:
comp_choice = "paper"
else:
comp_choice = "scissors"
print("Computer's choice is " + comp_choice + ".")
check_win(token, comp_choice, name_slice)
break
name_file.close()
#Outcomes function
def check_win(token, comp_choice, name_slice):
if token == comp_choice:
print("It's a Tie!")
elif token == "rock" and comp_choice == "scissors":
print(name_slice + "Wins with" + token + "!" + "\n..........")
elif token == "paper" and comp_choice == "rock":
print(name_slice + "Wins with" + token + "!" + "\n..........")
elif token == "scissors" and comp_choice == "paper":
print(name_slice + "Wins with" + token + "!" + "\n..........")
else:
print(name_slice + "is a loser with" + token + "\n..........")
check_input()
Aucun commentaire:
Enregistrer un commentaire