Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Python can\'t figure out how to fix the errors in this code to make it run id

ID: 3706488 • Letter: I

Question

In Python can't figure out how to fix the errors in this code to make it run idle. I'm stuck on line 4 it says it needs parenthesis but i've included them and I'm not sure what else may be wrong.

import random
#Generate a random integer between 10 and 100 to denote the initial size of the pile.
numOfMarbles = random.randint(10, 100)
print 'The size of the pile is: ',numOfMarbles
#Generate a random integer between 0 and 1 to decide wheter the computer or the human takes the first turn.
turn = random.randint(0, 1)
if turn == 0:
print 'Its the turn of a computer...'
else:
print 'Its your turn...'
#Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid.
stupidComputer = random.randint(0, 1)
if stupidComputer == 0:
print 'Remember. You are playing with a smart computer. Be alert...'
else:
print 'This computer is so stupid. Nothing to worry much...'
#In stupid mode the computer simply takes a random legal value (between 1 and n/2)
#from the pile whenever it has a turn.
while numOfMarbles != 1: #Till you're left with only one marble.
if turn == 0: #Computer turn
if stupidComputer == 1: #If the computer is playing in stupid mode.
temp = random.randint(1, numOfMarbles/2) #Select a random number between 1, and n/2.
else: # Select the marbles smartly.
if numOfMarbles - 3 > 0 and numOfMarbles - 3 < numOfMarbles/2:
temp = numOfMarbles - 3
elif numOfMarbles - 7 > 0 and numOfMarbles - 7 < numOfMarbles/2:
temp = numOfMarbles - 7
elif numOfMarbles - 15 > 0 and numOfMarbles - 15 < numOfMarbles/2:
temp = numOfMarbles - 15
elif numOfMarbles - 31 > 0 and numOfMarbles - 31 < numOfMarbles / 2:
temp = numOfMarbles - 31
else:
temp = numOfMarbles - 63
print 'The computer picked: %d marbles.' % temp #Print the marbles picked by computer.
numOfMarbles -= temp #Subtract the marbles picked by computer.
else:
marblesToPick = input('Its your turn. Pick the marbles in the range 1 - %d: ' % int(numOfMarbles/2)) #Read the marbles to be picked.
while marblesToPick < 1 or marblesToPick > numOfMarbles/2: #If read invalid value, try repeatedly.
marblesToPick = input('You picked the wrong count. Pick the marbles in the range 1 - %d: ' % int(numOfMarbles/2))
numOfMarbles -= marblesToPick #Subtract the marbles picked by you.
turn = (turn + 1) % 2 #Change the turn.
print 'Now the pile is of size %d.' % numOfMarbles
if turn == 0: #Declare the result.
print 'Yay. You made it. You won. Congrats...'
else:
print 'As always... The computer won. And you LOST...'

Explanation / Answer

print requires a parenthesis in PYTHON 3.0 onwards

CORRECT SYNTAX IS
print('The size of the pile is: ',numOfMarbles)

The Above Line will Work, Convert all print statement like Above and it will work.


Thanks, PLEASE UPVOTE if its helpful

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote