Question

3.plese to write the correct code: The code below will loop as long as the number...

3.plese to write the correct code:

The code below will loop as long as the number that you enter isn’t negative. It will add each non negative number to the current sum. It will print out the sum and average of all of the numbers you have entered. But someone jumbled up the code. Can you reorganize and indent it so it works properly?

count = count + 1
message = "Enter an integer or a negative number to stop"
value = input(message)
print("The sum is: " + str(sum) + " the average is: " + str(sum / count))
print("You entered " + value)
sum = sum + int(value)
count = 0
value = input(message)
while int(value) > 0:
sum = 0

Homework Answers

Answer #1
count = 0
sum = 0
message = "Enter an integer or a negative number to stop"
value = input(message)
while int(value) > 0:
    print("You entered " + value)
    sum = sum + int(value)
    count = count + 1
    value = input(message)
print("The sum is: " + str(sum) + " the average is: " + str(sum / count))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users...
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users guess value to zero so we enter the loop guess = 0 while guess == computer_num guess = input ("Enter a guess (1-10)") print("Correct the number is "+str(computer_num)) How many times will “Correct the number is…” print when this code block is executed?.
i need this code to print a number of stars depending on how much the user...
i need this code to print a number of stars depending on how much the user wants and after * it prints no stars. if the user enters a negative number it should print "error invalid number" this is my code so far: def stars(n,i): stars(n, 1) if n <= 0: return "No stars" if i <= n: print("* ", end="") stars(n, i + 1) else: print("no stars") stars(n - 1, 1) n = int(input("enter an integer")) def main(): stars()...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
C++ code please: Write a program to count the number of positive and the number of...
C++ code please: Write a program to count the number of positive and the number of negative inputs values. The program will stop when a 0 is input. Ex: If the input is -5.5 568 2.332 0 the output is 2 positive number(s) and 1 negative number(s). Ex: If the input is 153.0 0.534 2.2 5.6 46.584 0.015 5 0 the output is 7 positive number(s) and 0 negative number(s).
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
There are 3 types of iteration constructs. What ones did you use in your program, and...
There are 3 types of iteration constructs. What ones did you use in your program, and why? NUMS=4 i=1 lowMean=0 dayLow=0 dayHigh=0 highMean=0 highTemp=0 lowTemp=41 #Decalred required vriables print("--== Python Temperature Analyzer ==--") while(i<=4): high=int(input("Enter the high value of day"+str(i)+":")) low=int(input("Enter the low value of day"+str(i)+":")) #Reading high and low while(high>40 or high<-40 or low>40 or low<-40 or low>high): #if the conditons fails we again read the input print("Incorrect values, temperatures must be in the range -40 to 40, high...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking option entered by the user print("Enter 0 to 5 for following options: ") print("0-> Issue new ticket number.") print("1-> Assign first ticket in queue to counter 1.") print("2-> Assign first ticket in queue to counter 2.") print("3-> Assign first ticket in queue to counter 3.") print("4-> Assign first ticket in queue to counter 4.") print("5-> Quit Program.") tickets = [] #Declaring list to store...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...