question archive # Create a python script that will take a number from a user
Subject:Computer SciencePrice:3.86 Bought9
# Create a python script that will take a number from a user. If the given
# number is even, the script will continue to ask for numbers. If the number is
# odd the script will say goodbye and stop the script.
Insert your code on the space provided below.
#program to get even number from user, if odd then exit #while loop to get numbers from user while True: #promt user to enter the number number_str = input("Enter the number:") #convert number from string to integer number = int(number_str) #check if number is even or odd, #% operator gives denominator, #so if denominotor is 0 means its even number if number %2 == 0: #number is even so continue the loop continue else: #number is odd break from loop break #print Good bye message print("Good Bye")
Step-by-step explanation
1) Above program keep getting number from user, until numbers are even, if number is odd it exit with good bye message
2) Copy it in python file and run
3) Below is the test output
Test Output
Enter the number:2 //even number
Enter the number:10
Enter the number:20
Enter the number:24
Enter the number:14
Enter the number:7 //odd number exit