4.1 guessing game. Preset in the program integer between 0 to 9, so that the user through the keyboard guessing, if greater than the preset number, displays "Unfortunately, too big"; if less than the predetermined number, displays "Unfortunately, too small "; and so on, until the number guessed, displays" forecast N times, you guessed ", where N is the number of user input digits!.
= 4 Secret
#Print (Secret)
Print ( '! guessing game ------ -----')
NUM = the INPUT ( 'guessing game begin, enter numbers 0-9:')
GUESS = int (NUM)
N =. 1
the while Secret = GUESS:!
IF GUESS> Secret:
Print ( 'Unfortunately, too!')
the else:
( '! Unfortunately, too small') Print
NUM = INPUT ( 'guessing game start Please enter a number 0-9: ')
GUESS = int (NUM)
N = N +. 1
#Print (Secret)
Print ( '! guessing game ------ -----')
NUM = the INPUT ( 'guessing game begin, enter numbers 0-9:')
GUESS = int (NUM)
N =. 1
the while Secret = GUESS:!
IF GUESS> Secret:
Print ( 'Unfortunately, too!')
the else:
( '! Unfortunately, too small') Print
NUM = INPUT ( 'guessing game start Please enter a number 0-9: ')
GUESS = int (NUM)
N = N +. 1
print ( 'prediction {: .0f} times, you guessed it!' format (N).)
print ( 'the game is over, bye ^ _ ^!')
print ( 'the game is over, bye ^ _ ^!')
4.4 guessing game. Reprogramming exercises 4.1, let the computer randomly generates a preset number ranging between 0 and 100, other rules of the game change.
Random Import
Secret = random.randint (0,100)
#Print (Secret)
Print ( '------ guessing game! -----')
the TEMP = the INPUT ( 'guessing game begin, enter numbers 0- 100: ')
GUESS = int (TEMP)
N =. 1
the while Secret = GUESS:!
IF GUESS> Secret:
Print (' Unfortunately, too ')!
the else:
Print (' Unfortunately, too small ')!
TEMP = input ( 'guessing game start, enter a number 0-100:')
GUESS = int (TEMP)
N = N +. 1
Secret = random.randint (0,100)
#Print (Secret)
Print ( '------ guessing game! -----')
the TEMP = the INPUT ( 'guessing game begin, enter numbers 0- 100: ')
GUESS = int (TEMP)
N =. 1
the while Secret = GUESS:!
IF GUESS> Secret:
Print (' Unfortunately, too ')!
the else:
Print (' Unfortunately, too small ')!
TEMP = input ( 'guessing game start, enter a number 0-100:')
GUESS = int (TEMP)
N = N +. 1
Exception Handling 4.7 4.1 with a modified, so that it can receive and process any input from the user.
Random Import
Secret =. 4
#Print (Secret)
N =. 1
A = 1000
the while Secret = A:!
the try:
TEMP INPUT = ( 'guessing game start, enter a number 0-9:')
GUESS = int (TEMP)
IF GUESS> Secret:
Print ( 'Unfortunately, too!')
elif GUESS <Secret:
Print ( '! Unfortunately, too small')
elif == Secret GUESS: N = N +. 1 BREAK the except a ValueError: Print ( "IS Number Not ") N = N +. 1 Print ( 'prediction {: .0f}! views, you guessed'. format (N))
Secret =. 4
#Print (Secret)
N =. 1
A = 1000
the while Secret = A:!
the try:
TEMP INPUT = ( 'guessing game start, enter a number 0-9:')
GUESS = int (TEMP)
IF GUESS> Secret:
Print ( 'Unfortunately, too!')
elif GUESS <Secret:
Print ( '! Unfortunately, too small')
elif == Secret GUESS: N = N +. 1 BREAK the except a ValueError: Print ( "IS Number Not ") N = N +. 1 Print ( 'prediction {: .0f}! views, you guessed'. format (N))