World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Write a program to guess a number between 1 to 9 using elif.
Hint:
num = int(input("enter the number-->"))
if num == 1:
print(" ")
elif num == 2:
print(" ")
you have to guess the number using if elif else
number = input("Enter a number between 1 and 9: ") if number == "1": print("The number is 1.") elif number == "2": print("The number is 2.") elif number == "3": print("The number is 3.") elif number == "4": print("The number is 4.") elif number == "5": print("The number is 5.") elif number == "6": print("The number is 6.") elif number == "7": print("The number is 7.") elif number == "8": print("The number is 8.") elif number == "9": print("The number is 9.") else: print("The number is not between 1 and 9.")
This program will prompt the user to enter a number between 1 and 9, and then it will use a series of elif
statements to check if the number is one of the numbers between 1 and 9. If the number is one of the numbers between 1 and 9, the program will print the number; otherwise, it will print a message saying that the number is not between 1 and 9.