Write a menu-driven program to input a number,a character and choice to check as follows ----
Input a number ----
Press ‘d’ to check number is divisible by 4 or not.
Press ‘v’ to check character is vowel or not.
Enter choice -----
Answers
The following codes have been written using Python.
while True:
c = input("Enter a number/a character: ")
print()
print("Press 'd' to check if the number is divisible by 4 or not.")
print("Press 'v' to check if the character is a vowel or not.")
print()
ch = input("Enter your choice: ")
print()
if ch in 'dD':
if c.isalpha():
print(c, "is not a number.")
elif c.isnumeric():
n = int(c)
if n%4 == 0:
print(n, "is divisible by 4.")
else:
print(n, "is not divisible by 4.")
elif ch in 'vV':
if c.isnumeric():
print(c, "is not a character.")
elif c.isalpha():
if c in 'AEIOUaeiou':
print(c, "is a vowel.")
else:
print(c, "is not a vowel.")
print()
nc = input("Would you like to go again? [Y/N]: ")
print()
if nc in 'Yy':
continue
else:
break
Menu-driven programs are usually created using a loop. Once the character and choice have been entered, a conditional statement is passed to check what choice the user wants. Appropriate conditional statements are passed again to test if the character is suitable for the requested choice.