Question

In: Computer Science

PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to...

PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to be processed. If ?≤0 your program must display an error message and terminate; otherwise it does the following for ? times:

  • Write a program that prompts for and reads the number ?n of spheres to be processed. If ?≤0n≤0 your program must display an error message and terminate; otherwise it does the following for ?n times:
    • Prompts for and reads the volume of a sphere, it then displays the surface area of the sphere with that volume. Assume that each volume is in cubic centimeters.
  • The program finally displays the average of the surface areas of the ?n spheres.
  • Please note that
    • ?=3.14159π=3.14159.
    • volume =43??3=43πr3.
    • surface area =4??2=4πr2.
  • The following are sample runs of the program.

Solutions

Expert Solution

#user input for number of spheres
noOfSpheres = int(input("How many spheres? "))

#if no of spheres is 0 or less it will terminate with error msg
if(noOfSpheres <= 0)  :
    print("Number of spheres must be 1 or more.")
    #to terminate program
    quit()
   
#to store volume of each sphere
volumeList = []

#user input of volume for each sphere
for i in range(noOfSpheres):
    
    #it will ask for volume and store it in volume variable
    volume = input("Enter Volume for shere " + str(i+1) + " in cubic centimeters : ")
    
    #add entered volume in volumeList
    volumeList.append(volume)

#to store area for each sphere    
areaList = []

#constant value of PI
PI = 3.14159

#to store average surface area
avg = 0

#to maintain sphere counter
i = 0

#find surface area for each sphere and calculate average surface area
for volume in volumeList :
    
    #to calculate radius
    radius = ((3 * float(volume))/(4 * PI))**(1/3)
    
    #to calculate area
    area = 4 * PI * (radius)**2
    
    #to calculate total sum of surface area
    avg = avg + area
    
    #sphere counter is increamented by 1
    i = i + 1
    
    #prints area of each sphere
    print("area for sphere " + str(i) + " is : " + str(area))
    
    #add area in areaList
    areaList.append(area)

#calculating final average sphere area value
avg = avg / noOfSpheres

#prints avearge sphere surface area
print("Average area for all spheres : " + str(avg))

Sample output :


Related Solutions

Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August. The file climate_data_2017_numeric.csv contains the following fields: Date Minimum temperature (C) Maximum temperature (C) Rainfall (mm) Speed of maximum wind gust (km/h) 9am Temperature (C) 9am relative humidity (%) 3pm Temperature (C) 3pm relative humidity (%) Expected...
Write a Java program that prompts for and reads the number N of cities or locations...
Write a Java program that prompts for and reads the number N of cities or locations to be processed. It then loops N times to prompt for and read, for each location, the decimal latitude, decimal longitude, and decimal magnetic declination. It then computes and displays, for each location, the Qibla direction (or bearing) from Magnetic North. The true bearing from a point A to a point B is the angle measured in degrees, in a clockwise direction, from the...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Write a program that prompts for and reads in the two side lengths of a right...
Write a program that prompts for and reads in the two side lengths of a right triangle (floating point numbers) and then calls a float-valued function, hypot1, that calculates and returns the length of the hypotenuse of the triangle. The program then displays the two side lengths and the hypotenuse length. Note: The hypot1 function returns the hypotenuse length – it does not display it; the function should not contain any cout nor cin statements. Math review: Recall that for...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs...
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs and prints the number of even and odd inputs in the sequence. please explain. Thanks
Write a Python program that reads an integer and prints how many digits the number has,...
Write a Python program that reads an integer and prints how many digits the number has, by checking whether the number is ≥10,≥100,≥1000, and so on (up to 1,000,000). Your program should also identify if a number is negative.
USING PYTHON ONLY Part 3a: Prime Number Finder Write a program that prompts the user to...
USING PYTHON ONLY Part 3a: Prime Number Finder Write a program that prompts the user to enter in a postive number. Only accept positive numbers - if the user supplies a negative number or zero you should re-prompt them. Next, determine if the given number is a prime number. A prime number is a number that has no positive divisors other than 1 and itself. For example, 5 is prime because the only numbers that evenly divide into 5 are...
Write a program(Python) using functions and mainline logic which prompts the user to enter a number....
Write a program(Python) using functions and mainline logic which prompts the user to enter a number. The number must be at least 5 and at most 20. (In other words, between 5 and 20, inclusive.) The program then generates that number of random integers and stores them in a list. The random integers should range from 0 to 100. It should then display the following data to back to the user with appropriate labels: The list of integers The lowest...
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT