Mistakes in doing after-class questions: the result I expect is that the program is running normally and there are three opportunities to guess numbers.

topic description

mistakes in doing after-class questions for small turtles

sources of topics and their own ideas

the source is the fifth post-class question for the little soft-shelled turtle.
my idea is to first define a variable, then assign a value to it, and then determine whether the variable is an integer or not. If the input is incorrect and the display is illegal, enter it again. When all the characters entered are numbers, continue to run down. And there are only three chances.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

print("C........................")
import random
secret=random.randint(1,10)
temp=input(":")
count=3
while count:
    while not guess.isdigit():
        temp=input(":")
guess=int(temp)
    if guess==secret:
        print("")
        break
    else:
        if guess>secret:
            print("",end="")
        else:
            print("",end="")
        count-=1
        print("%d:"%count,end=" ")
        guess=int(input())
    if count==1:
        break
if count==1:
    print("")
    print("%d"%secret,end=" ")

what result do you expect? What is the error message actually seen?

what I expect is that the program runs normally and has three chances to guess numbers. What you actually see is:

 File "C:\Users\Desktop\\3.py", line 10
    if guess==secret:
    ^
IndentationError: unexpected indent
Mar.29,2021

Indentation means indentation. IndentationError so maybe there's something wrong with your indentation, mixing tab with spaces.

by the way, there is also a problem with the code paste when asking a question. Some of the code is not included in the code display block

.

retypeset you

-sharp!/usr/bin/env python
-sharp -*- coding: utf-8 -*-

print('C........................')
import random
secret=random.randint(1,10)
temp=input(':')
count=3

while count:
    while not temp.isdigit():
        temp=input(':')
        guess = int(temp)
        if guess==secret:
            print('')
            break
        elif guess>secret:
                print('',end='')
        else:
            print('',end='')
    count-=1
    print(count)
    print('%d:'%count,end=' ')
    guess=int(input())
    if count==1:
        print('')
        print('%d'%secret,end=' ')
        break

the execution result is as follows

:7
2
2: 9
1
1: 2

3 

in addition, you can be familiar with the markdown, code to avoid format confusion

Menu