1. Add two numbers and store the answer in a variable named SUM. Ask the user to input two values. Read in the first number and store it in a variable named num1, read in the second number and store it in a variable named num2. Check to see if each of the numbers you read are a zero, if they are ask the user to in put a different number.

2. Add and print the class average. Store the class average in a variable named Average. Create a counter to count the number of grades that were entered and store it in the variable counter. Create a loop to enter each grade. Terminate the loop once it reaches 50 iterations.

3. Check to see if the number the user inputs is positive or negative. Ask the user to input a number. Read and store the number in a variable named NUM. Check to see if the number is positive, negative, or zero. Output a phrase to the user telling them if the number is positive, negative, or zero.

Respuesta :

The answers to the programs that

  • Accepts two numbers from the user and sums them up if neither are zero
  • Accepts 50 grades and calculates their average
  • Gets a number from the user and prints the sign of the number (that is, if the number is positive, negative or zero)

were written in Python 3.8, and can be found in the attached images

The first program uses a function get_input() to get the input for each number before they are added up. The function uses a while loop to make sure that the user does not enter zero.

Whenever the user enters zero, a message is displayed that says

"number should not be zero, Try again"

then the while loop repeats.

The next program uses a while loop and a variable named counter to keep track of the number of grades entered by the user.

Inside the loop, each time the user enters a number, it is added up to the previous sum, and the counter is incremented by one to keep track of the number of grades entered so far.

Once the loop completes, the average is then calculated from the accumulated sum. the average is computed by dividing that sum by the counter.

The third and final program uses an if statement to check the sign of the number entered by the user. Then it prints out an appropriate message.

The if statement tests for the conditions as follows

  • If NUM > 0, then NUM entered was positive, and print "The number you entered is positive"
  • else If NUM < 0, then NUM entered was negative, and print "The number you entered is negative"
  • else NUM = 0, then NUM entered was zero, and print "You entered zero"

Another Python program about sums can be found here: https://brainly.com/question/6224293

Ver imagen batolisis
Ver imagen batolisis
Ver imagen batolisis
ACCESS MORE