I think the code is correct for python in idle, just need help with the correct
ID: 3708167 • Letter: I
Question
I think the code is correct for python in idle, just need help with the correct indentation and errors.
def main():
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("Vs Smart computer")
else:
print("Vs Dumb computer")
#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("the pile is of size %d.") % numOfMarbles
if turn == 0: #Declare the result.
print("You won.")
else:
print("The computer won")
main()