Question

don't use continuity and break in python 3:• xercise Write a program that prompts for and reads the number n of spheres to be processed. If n < 0 your program must disp (In python3) Exercise # 4: 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: 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 ? spheres.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import math

#taking user input
n = int(input('Enter number of spheres to be processed: '))

if(n<=0):
    print('number of spheres must be > 0')
else:
    i = 1
    pi = 3.14159
    sa_sum = 0#sum of all the surface areas
    while(i<=n):
        v = float(input('Enter volume of sphere {}: '.format(i)))
        # calculating the value of r:
        r = math.pow(((3*v)/(4*pi)),1/3)
        #calculating surface area
        sa = 4*pi*r*r
        sa_sum = sa_sum + sa
        #displaying surface area
        print('Sphere #{} surface area= {}'.format(i,round(sa,2)))
        i = i + 1
    
    #calculating average surface area
    avg_sa = sa_sum/n
    print('The average surface area = {}'.format(round(avg_sa,2)))
    

output:[Pratyushs-MacBook-Pro:python pthapli$ python3 test.py Enter number of spheres to be processed: -1 number of spheres must be

Code screenshot:

leggmg ? Py 1 2 import math 3 #taking user input n = int(input(Enter number of spheres to be processed: )) 4 5 6 7 8 9 10 1

Add a comment
Know the answer?
Add Answer to:
don't use continuity and break in python 3: (In python3) Exercise # 4: Write a program...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • Problem 3 (5 points) Write a program that prompts the user for the radius of a...

    Problem 3 (5 points) Write a program that prompts the user for the radius of a sphere. Your program should then compute values for the area, and volume of the sphere. Your program should then output the results for the sphere area, and volume. Enter the radius of the sphere as a real number? 10.5 The area of a sphere with radius 10.5 is 1385.44 The volume of a sphere with radius 10.5 is 4849.05

  • important don't use arrays or listed pleaseeeee in python 3 Write a program that given a...

    important don't use arrays or listed pleaseeeee in python 3 Write a program that given a collection of ?N numbers will find the largest value, its frequency and the average of the ?N numbers. Get the value of ?N from the user. If ?≤0N≤0, display an appropriate error message and terminate the program; otherwise Read the values as entered from the user. (If ?=5N=5, then there are 5 values the user is going to enter). Find the largest, its frequency...

  • A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is...

    A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is mapped, row-wise, to a 1D-array of size 28: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Implement a well-structured C program to enable a user to make and cancel seat reservations for the bus. The program uses a text-file seats.txt to store the reservation...

  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume...

    Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • In Python 3, Write a program that reads a set of floating-point values. Ask the user...

    In Python 3, Write a program that reads a set of floating-point values. Ask the user to enter the values, then print: The number of values entered. The smallest of the values The largest of the values. The average of the values. The range, that is the difference between the smallest and largest values. If no values were entered, the program should display “No values were entered” The program execution should look like (note: the bold values are sample user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT