selection for loops

How to pick the loop:

1, if the fixed number, for use

2, if you must run once, with do __while

3, while other cases with

The purpose is to make rigorous logic, clear structure, with pytthon example:

1、

# Determined digital inputs are few,
'' '

num = int (input ( "Enter need to determine the number:"))
n-= 0
IF NUM> 0:
    the while NUM> 0:
        n-+ =. 1
        NUM // = 10
the else:
    n-=. 1
Print (n-)    
'' '
NUM = int (input ( "enter number of judgment:"))
n-=. 1
the while NUM> = POW (10, n-):
    n-+ =. 1
Print (n-)

2、

# Guess
Import Random
Print ( "guessing game begins, you have six opportunities \ the n-")
target = random.randint (0,101)
gnum = int (the INPUT ( "Please enter your first integer:"))
I in Range for (. 6):
    IF gnum == target:
        IF I <= 2:
            Print (. "!} {times on only guessed, genius" the format (I +. 1))
        elif. 3 <= I <. 5 :
            Print ( "{} at times before guessed it, pretty clever it!" format (i + 1).)
        the else:    
            . Print ( "! {} times run out before all the guess right, you have to work oh" format (I +. 1))
        BREAK   
    the else:
        IF I <. 5:
            IF gnum> target:
                gnum = int (INPUT ( "number is too large, there are chances {}:" .format (. 5-I)))
            elif gnum < target:
                gnum = int (INPUT ( "small numbers, there are chances {}:."format(5-i)))
        else:
            print ( "! \ n six times already guessed, alas the answer is:", target)

Guess you like

Origin www.cnblogs.com/lamboo-wam/p/11784403.html