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....
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...
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...
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...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of a number. * function name: get_fact * parameters: num (int) * returns: int * operation: Must use a loop here. Essentially calculate and return the factorial of whatever number is provided. but: - If num is less than 1 or greater than 20, print "num is out of range" and exit the function - If num is not an int, print "invalid num parameter"...
Two conducting spheres are each given a charge Q. The radius of the larger sphere is...
Two conducting spheres are each given a charge Q. The radius of the larger sphere is three times greater than that of the smaller sphere. If the electric field just outside of the smaller sphere is E0, then the electric field just outside of the larger sphere is: E0 1/3 E0 9 E0 3 E0 1/9 E0
Charges Q1 and Q2 are uniformly distributed in two half of a sphere with radius R....
Charges Q1 and Q2 are uniformly distributed in two half of a sphere with radius R. The two halves rotate around the z-axis with each spinning in opposite directions. The half spheres have angular velocities ω1 and ω2. Using Biot Savart law, find the magnetic field at the center of the sphere.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT