Question

In: Computer Science

#Sphere – pi and radius Create two python programs named program_1 and program_2 that will calculate...

#Sphere – pi and radius

Create two python programs named program_1 and program_2 that will calculate the surface area of a sphere. The programs will use user-defined functions. Global variables are NOT allowed in either program. Program_1 will be listed first in the answer box with Program_2 written below it. Separate the programs with a line of dashes ( --------------------------------------------- ) as shown in the example below.

Program_1 will:

  1. Prompt the user for the radius of the shape and store the variable as “rad”
  2. Call a user-defined function (UDF) within the program to calculate the surface area of the shape. The UDF will have an input of radius and will receive the value of pi from a second UDF.
  3. Call a second user-defined function (from inside the first UDF) that is in program_2 that will produce the value of pi
  4. The first UDF will then calculate the surface area of the shape and return the surface area to the main program.
  5. Print the value of the radius and surface area from the main program

Program_2 will

  1. Use a user-defined function that will store the value of pi in a variable named “pi_val”
  2. Sends the output of the value of “pi_val” back to program_1

Solutions

Expert Solution

#program_1

#import all function of program_2
from program_2 import *

#user defined function for calculating surface area of the sphere
def surface_area(rad):

    #calls the getpivalue function from program_2 file
    pi = getpivalue()

    #calculates surface area of sphere that is 4 * pi * rad * rad
    ans = 4 * pi * rad *rad

    #return area of the sphere stored in ans variable
    return  ans

#takes radius eterd by user
rad = float(input("Enter the radius: "))

#prints Radius and surface area of the sphere
print("Radius: ", rad , "Surface Area: {:.2f}".format(surface_area(rad)))




-----------------------------------------------------------------------------------

#program_2

import math

#user define function that returns pi value
def getpivalue():

    #stores the value of pi in pi_val variable
    pi_val =  math.pi

    #return pi_val
    return  pi_val

I have run this code in pycharm editor. You can run in any editor of your choice.

program_1.py

program_2.py

OUTPUT:


Related Solutions

In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program,...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program called randomwrite.py that writes a series of random integers to a file....
1. A flywheel is the shape of a sphere of radius R. Calculate the stored energy...
1. A flywheel is the shape of a sphere of radius R. Calculate the stored energy again for rotation time T and total mass M. Do not attempt to use moment of inertia or rotational mechanics, do it the way we did in class. 2. Find an exercise calorie website, and for a 70 kg person walking on a treadmill at 5 kilometers per hour, by varying the grade of the treadmill, plot the work output power (of lifting the...
in python please Q1) Create a Singly link list and write Python Programs for the following...
in python please Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if...
Create a Python Module named piphash_rainbow.py that Creates a rainbow table named sixdigithash_rainbow.csv that stores all...
Create a Python Module named piphash_rainbow.py that Creates a rainbow table named sixdigithash_rainbow.csv that stores all possible six-digit pins and their corresponding md5, sha1, sha256, and sha512 hashes.
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using...
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using a NumericUpDown. Have the function calculate the surface area and display it on your page. Label the inputs and the output on your page. Change the title to "Oh, Boy! JavaScript!". Put your name at the top in camelCase. Put your major at the bottom in camelCase.
A sphere with radius a = 8 cm is in a conductive sphere shell with an...
A sphere with radius a = 8 cm is in a conductive sphere shell with an internal radius of b = 12 cm and an outer radius of c = 18 cm with a load of -200 mC. a) Determine the load distribution in the sphere and sphere shell. b) Calculate the value of the electric field in r = 0 cm, r = 4 cm, r = 8 cm, r = 10 cm, r = 14 cm, r =...
Create a class called Sphere. The class will contain the following    Instance data double radius...
Create a class called Sphere. The class will contain the following    Instance data double radius Methods Constructor with one parameter which will be used to set the radius instance data Getter and Setter for radius             Area - calculate the area of the sphere (4 * PI * radius * radius)             Volume - calculate and return the volume of the sphere (4/3 * PIE * radius * radius * radius) toString - returns a string with the...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
​​​​Python Create a new file named compute_cost.py. Write your name and date in a comment. Create...
​​​​Python Create a new file named compute_cost.py. Write your name and date in a comment. Create a variable named base_fee and set the value to 5.5. Prompt the user for the zone. The zones can be an integer value from 1 to any value for the zone. Convert the zone to an integer. Display the zone on the SenseHat with a scroll speed of 0.3, make the text blue, and the background yellow. Scroll "The zone is " and the...
A sphere with radius a has uniform charge/volume. A metal sphere shell has inner radius b(from...
A sphere with radius a has uniform charge/volume. A metal sphere shell has inner radius b(from center) and outer radius c(from center). Between a and b is empty. Outer metal shell has total charge Q1 Please start with Gauss's law and show steps Find Electric field in region a) r<a b)a<r<b c)b<r<c d) r>c
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT