Question

In: Computer Science

write a program that: 1) asks the user to enter grades, a negative number is the...

write a program that:

1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list)

after the while loop to enter grades is finished:

2) use a for loop on the list to calculate the average of all numbers in the list

3) use a for loop on the list to find the largest number in the list

4) use a for loop on the list to find the smallest number in the list

your program should have 1 while loop and 3 for loops

python code

Solutions

Expert Solution

Python code:

#initializing a grades list
grades=[]
#accepting the grade
num=int(input("Enter the grade: "))
#looping till a negative number is entered
while(num>=0):
#adding it to list
grades.append(num)
#accepting the grade
num=int(input("Enter the grade: "))
#initializing sum as 0
sum=0
#looping all grades
for i in grades:
#adding current number to sum
sum+=i
#printing Average
print("Average:",sum/len(grades))
#initializing max as 0
max=grades[0]
#looping all grades
for i in grades:
#checking if the current number is the maximum
if(i>max):
#assigning current number as maximum
max=i
#printing Largest number
print("Largest number:",max)
#initializing min as 0
min=grades[0]
#looping all grades
for i in grades:
#checking if the current number is the minimum
if(i<min):
#assigning current number as minimum
min=i
#printing Smallest number
print("Smallest number:",min)


Screenshot:


Input and Output:


Related Solutions

Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
In C#, write a console-based program that asks a user to enter a number between 1...
In C#, write a console-based program that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined where you...
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
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
1/Write a C program that asks the user to enter 5 nums and adds each number...
1/Write a C program that asks the user to enter 5 nums and adds each number to a total. The program should then display the total. To add to the total, the program must call the function void sum(int value, int *ptotal) passing the value the user entered and the address of the total (a local variable in main). The function should add the value to the total. Note that the function is void and does not return anything. Don't...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Develop a program that asks a user to enter the number 10, and then it outputs...
Develop a program that asks a user to enter the number 10, and then it outputs COUNT-DOWN from 10 to 0. using for-loop
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT