Question

In: Computer Science

USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...

USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is even", if odd print "odd". The loop will test 5 numbers.

All one program, so a for loop nested in a while loop I think.

Solutions

Expert Solution

quitVariable = 'y'

while quitVariable == 'y' or quitVariable == 'Y':
    even_count = 0
    odd_count = 0
    for i in range(5):
        n = int(input("Enter a positive integer: "))
        if n % 2 == 0:
            print("number is even")
        else:
            print("number is odd")
    quitVariable = input("Do you want to try again(y or n): ")
    print()
print("Thanks for playing!")


Related Solutions

python: ask the user to input a sequence of positive numbers. the end of the sequence...
python: ask the user to input a sequence of positive numbers. the end of the sequence is determined when the user enters a negative number. print out the maximum number from the sequence. output: keep entering positive numbers. to quit, input a negative number. enter a number: 67 enter a number: 5 enter a number: 8 enter a number: -3 largest number entered: 67 (note: i do not want to ask the user how many numbers they will input)
In your python program, ask the user to enter the annual income of an employee and...
In your python program, ask the user to enter the annual income of an employee and the years of experience. Pass these data to a function. The function decides if an employee does qualify for a loan or does not, then it prints a message based on the following rules: If the income is equal or greater than $40000, the function checks if the employee’s years of experience is greater than 4, if so the employee gets $6000 loan; otherwise,...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList. b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers...
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
Task 1. creating a nested if:   Need a python program that ask the user to enter...
Task 1. creating a nested if:   Need a python program that ask the user to enter the annual income of an employee and the years of experience. Pass these data to a function. The function decides if an employee does qualify for a loan or does not, then it prints a message based on the following rules: If the income is equal or greater than $40000, the function checks if the employee's years of experience is greater than 4, if...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that in array. Display that all numbers before and after performing Bubble sort. You must have to create new function with required parameter to perform Bubble sort. Sample Run :- Enter 1 number :- 1 Enter 2 number :- 5 Enter 3 number :- 7 Enter 4 number :- 45 Enter 5 number :- 90 Enter 6 number :- 6 Enter 7 number :- 55...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT