4. Write a python program to guess a number between 1 to 10. When guessing correctly, pop out a message to inform the user. One of the example can be seen in the following output:
One of the example output is:
Expected Answer:
Guess a number between 1 and 10 until you get it right : 5
Guess a number between 1 and 10 until you get it right : 6
Guess a number between 1 and 10 until you get it right : 7
Guess a number between 1 and 10 until you get it right : 8
Guess a number between 1 and 10 until you get it right : 9
Guess a number between 1 and 10 until you get it right : 10
Congratulations, you guess correctly!
Sample Answer:
import random target_num, input_num = random.randint(1, 11), 0 while target_num != input_num: input_num = int(input('Guess a number between 1 and 10 until you get it right : ')) print('Congratulations, you guess correctly!')
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)