Related questions
Write a
This must be written in Python. I have most of it figured out, I just don't know how to add an accumulator for the odd and even numbers. I have attached what I have so far below. Thank you!
def main():
TOTAL = 0
print('This program calculates all odd and even positive numbers entered')
num = int(input('Enter a positive number or 0 to quit: '))
while num != 0:
if num % 2 == 0:
print(f'This {num} is even')
else:
print(f'This {num} is odd')
num = int(input('Enter a positive number or 0 to quit: '))
total_even = num % 2 == 0
total_odd = num % 2 != 0
total_even_num = total_even + num
total_odd_num = total_odd + num
print(f'Your total of even number is {total_even_num}')
print(f'Your total of odd numbers is {total_odd_num}')
main ()
Step by stepSolved in 4 steps with 2 images
- For this question you must design and implement a postcondition loop in Python that will display the following numbers (one on each line) to the terminal: 29, 41, 53, 65, 77, 89, 101, 113, 125, 137, 149, 161, 173, 185, 197, 209, 221, 233, 245, and 257. Although a counter-controlled loop is ideal for this task, you are not permitted to use a FOR loop in your program - you must use a postcondition loop that has been implemented using WHILE instead.Furthermore, your postcondition loop must be implemented using a Boolean flag variable.arrow_forwardPlease answer Question 2arrow_forwardI am having trouble coding this assign assignment in Python. The code that I have in the image gives infinite loops is incorrect. I need help coding thisarrow_forward
- Please write a program which asks the user for a number. The program then prints out all integer numbers greater than zero but smaller than the input. Upper limit: 5 1234 4 Sample output Please don't use the value True as the condition of your while loop in this exercise!arrow_forwardconsider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a consecutive duplicate. Write some code that use a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code finishes executing, the number of consecutive duplicates encountered is printed. using Pythonarrow_forwardWrite Python statements that use a for loop, make the variable x go from -10 to 10, counting by 2. Inside the body of the loop, make another variable y become the current value of x squared. Then display the current values of x, y and their sum. Try to use appropriate spacing but it doesn't affect your point that you can get from this part. Part-2: Sum |-10 100 90 -8 64 56 |-6 36 30 -4 16 12 |-2 4 2 2 4 4 6 16 20 36 42 8 10 72 Window 64 100 110 Windows'uarrow_forward
- Is there a way for a programmer to recognize an infinite loop and break out of it?arrow_forwardWrite a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop to allow the user to enter numbers, one at a time, until some numeric sentinel value is entered. I recommend having a sentinel like 9999, something unlikely to be confused with an exam score. If the user enters a score < 0 or > 100 that is not the sentinel value then that score is to be rejected. Each time a legit score is entered, however, it should be added (appended) to a list. Once the user has entered all the numbers they want, calculate and display the average of the scores rounded to 1 decimal place. I attached my solution. I can not fix two...arrow_forwardI want to Write a program in pthat asks the user for the speed of a car (in miles per hour) and the number of hours it has traveled. After it i want to use a loop to show the distance the car has traveled for every hour of that time periodarrow_forward
- Write a program in Python that sums a series of (positive) integers entered by the user, excluding all numbers that are greater than 100. We are going to use a sentinel value (also known as a flag value) to control the loop. If the user wants to quit summing up numbers, the user will enter a (-1). The first line should print out a title that says something like "Practice 3: summing positive values entered by the user that are less than 100". For this practice you only can use while loop as you don’t know how many numbers the user wants to enter. A sample output is below.arrow_forwardWrite a python program that uses while loops to display the number of bugs collected throughout 5 days. In addition to displaying the total number of bugs collected, display the average number of bugs collected per day. The average should be displayed with 1 digit to the right of the decimal.arrow_forwardWrite a program using while loop. You should ask a user to enter a number as an input and in each loop iteration, divide the number by 2, then print the numbers. While loop should repeat as long as the number each step is greater than or equal to 1.. Sample output with input: 30 20.0 10.0 5 2.5 1.25 0.625arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education