In: Computer Science
python programming.
Write a program that prompts the user to enter an integer from 0 to 9. The program will check if the input is a positive integer. It displays the correct answer and shows the guess is correct or not. The demos are shown as following.(Hint:1. Use a random math function 2. Use str.isdigit() to check the input)
# Python Code:-
import random
def main():
# Creating a random number from 0 to 9 which acts as a
guess number.
guess = random.randint(0,9)
# Prompt user to enter an integer from 0 to
9
string = input("Enter a number : ")
# The program will check the number is positive integer or
not
# If the input number is positive number.
if string.isdigit()==True:
# Convert the string into number that is between 0 to
9
number = int(string)
# Check the input numeber is equal to the guess number or
not.
# If both are equal
if number == guess:
print("Guess is Correct")
# If both are not equal
else:
print("Guess is not Correct")
# If the number is not positive
else:
print("Number is not positive")
if __name__=="__main__":
main()