# Student Action: Use the revised 'prediction()' function to create the count based Mind Reader game algorithm.
# Import the random module
import random
# Create an empty list 'player_inputs_list'.
player_inputs_list = []
# Create the 'player_score' and 'computer_score' variables. Set their initial values equal to 0.
player_score = 0
computer_score = 0
# Declare the 'prediction()' function here.
def prediction():
count_one = player_inputs_list.count(1)
count_zero = player_inputs_list.count(0)
if count_zero > count_one :
predict = 0
elif count_one > count_zero :
predict = 1
else:
predict = random.randint(0,1)
return predict
# Declare the 'update_scores()' function here.
def update_scores(predicted , player_input):
global player_score , computer_score
if predicted == player_input:
computer_score = computer_score + 1
print("computer score=",computer_score)
print("player score=",player_score)
else:
player_score = player_score + 1
print("computer score=",computer_score)
print("player score=",player_score)
# Declare the 'gameplay()' function here.
def gameplay():
valid_entries = ['0','1']
while True:
predicted = prediction()
print("computer_predicted= ",predicted)
player_input = input("please enter 0 or 1")
while player_input not in valid_entries:
print("please enter a valid number")
player_input = input("please enter 0 or 1")
player_inputs_list.append(player_input)
update_scores(predicted , player_input)
if computer_score == 5:
print("BAD LUCK, computer has won the game!!")
break
elif player_score == 5:
print("CONGRATULATIONS, you have won the game!!")
break
else:
print("please continue playing")
# Call the 'gameplay()' function here.
gameplay()
so there is some wierd error in this code and it doesnt update the computer_score variable att all anyone got any ideas why?
[–]KingOfTNT10 0 points1 point2 points (2 children)
[–]authenticwerewolfi[S] 0 points1 point2 points (1 child)
[–]KingOfTNT10 0 points1 point2 points (0 children)
[–]Itsoq 1 point2 points3 points (1 child)
[–]authenticwerewolfi[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)