Hi
I need some help, not sure what I can do to fix this code.
import random
gamerun = 1
playername = 1
roundask = 1
topicchoice = 1
question = 1
answered = []
count = 0
p1score = 0
p2score = 0
restart = 1
while gamerun == 1:
playername = 1
roundask = 1
topicchoice = 1
question = 1
answered = []
count = 0
p1score = 0
p2score = 0
restart = 1
rounddone = 1
p1 = input (' What is your name?')
p2 = input (' What is your name?')
while roundask == 1:
roundchoice = input('How many rounds would you like to play?')
if roundchoice == '1':
roundchoice = 1
roundask = 0
elif roundchoice == '2':
roundcount = 2
roundask = 0
elif roundchoice == '3':
roundchoice = 3
roundask = 0
else:
print ('You can choose 1, 2 or 3 rounds')
while rounddone <= roundchoice:
while topicchoice == 1:
choice = input ('topic choices are: Animals, Sports Brands and Sports ')
if choice == 'Animals':
topic = open ('Animals.txt', "r")
topicchoice = 0
elif choice == 'Sports Brands':
topic = open ('Sports Brands.txt', "r")
topicchoice = 0
elif choice == 'Sports':
topic = open ('Sports.txt', "r")
topicchoice = 0
else:
print (' Please choose a valid topic ')
turn = (random.choice([p1, p2]))
while question < 5:
print ("it is",turn,"'s turn" )
playeranswer = input (' Make a guess! ')
for line in topic:
if playeranswer in answered:
print ('Answered')
elif playeranswer in line:
print ('Correct!!')
question = question + 1
count = count + 1
answered.append(playeranswer)
else:
print('Incorrct!!')
if turn == p1:
p1score = p1score + count
turn = p2
count = 0
elif turn == p2:
p2score = p2score + count
turn = p1
count = 0
if turn == p1:
p1score = p1score + count
turn = p2
count = 0
rounddone = rounddone + 1
elif turn == p2:
p2score = p2score + count
turn = p1
count = 0
rounddone = rounddone + 1
while restart == 1:
askreplay = input ('Would you like to play again?')
if askreplay == 'yes':
restart = 0
elif askreplay == 'no':
restart = 0
gamerun = 0
else:
print('yes or no')
This is an assignment I have to hand in pretty soon, and it's really hard for my level so I'm having difficulties running it, if someone could help me it'd be much appreciated. Thank you.
Purpose/Details:
In this game you are to load a series of categories and responses based on topic. The player is then given a topic and asked to pick the top 5 responses if they get one incorrect the opposing player may guess. This continues until all 5 responses are found. The player with the most responses wins.
The game must read in the categories and responses from a specified text file. It should then allow players to enter their name and select up to 3 rounds. At the end it declares a winner.
I need some help, not sure what I can do to fix this code.
import random
gamerun = 1
playername = 1
roundask = 1
topicchoice = 1
question = 1
answered = []
count = 0
p1score = 0
p2score = 0
restart = 1
while gamerun == 1:
playername = 1
roundask = 1
topicchoice = 1
question = 1
answered = []
count = 0
p1score = 0
p2score = 0
restart = 1
rounddone = 1
p1 = input (' What is your name?')
p2 = input (' What is your name?')
while roundask == 1:
roundchoice = input('How many rounds would you like to play?')
if roundchoice == '1':
roundchoice = 1
roundask = 0
elif roundchoice == '2':
roundcount = 2
roundask = 0
elif roundchoice == '3':
roundchoice = 3
roundask = 0
else:
print ('You can choose 1, 2 or 3 rounds')
while rounddone <= roundchoice:
while topicchoice == 1:
choice = input ('topic choices are: Animals, Sports Brands and Sports ')
if choice == 'Animals':
topic = open ('Animals.txt', "r")
topicchoice = 0
elif choice == 'Sports Brands':
topic = open ('Sports Brands.txt', "r")
topicchoice = 0
elif choice == 'Sports':
topic = open ('Sports.txt', "r")
topicchoice = 0
else:
print (' Please choose a valid topic ')
turn = (random.choice([p1, p2]))
while question < 5:
print ("it is",turn,"'s turn" )
playeranswer = input (' Make a guess! ')
for line in topic:
if playeranswer in answered:
print ('Answered')
elif playeranswer in line:
print ('Correct!!')
question = question + 1
count = count + 1
answered.append(playeranswer)
else:
print('Incorrct!!')
if turn == p1:
p1score = p1score + count
turn = p2
count = 0
elif turn == p2:
p2score = p2score + count
turn = p1
count = 0
if turn == p1:
p1score = p1score + count
turn = p2
count = 0
rounddone = rounddone + 1
elif turn == p2:
p2score = p2score + count
turn = p1
count = 0
rounddone = rounddone + 1
while restart == 1:
askreplay = input ('Would you like to play again?')
if askreplay == 'yes':
restart = 0
elif askreplay == 'no':
restart = 0
gamerun = 0
else:
print('yes or no')
This is an assignment I have to hand in pretty soon, and it's really hard for my level so I'm having difficulties running it, if someone could help me it'd be much appreciated. Thank you.
Purpose/Details:
In this game you are to load a series of categories and responses based on topic. The player is then given a topic and asked to pick the top 5 responses if they get one incorrect the opposing player may guess. This continues until all 5 responses are found. The player with the most responses wins.
The game must read in the categories and responses from a specified text file. It should then allow players to enter their name and select up to 3 rounds. At the end it declares a winner.