Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.) Write a function called convert from copper that takes a single integer argument representing a number of copper pieces. The function prints out the

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

4.) Write a function called convert from copper that takes a single integer argument representing a number of copper pieces. The function prints out the number of gold pieces (gp). silver pieces (sp), and copper pieces (cp) you would end up with if you first converted as many of the initial copper pieces to gold as possible and then converted as many of the remaining copper pieces as possible to silver pieces. Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): convert from copper (200) 200 copper pieces is: 4 gp, Osp, cp convert from_copper (1107) 1107 copper pieces is: 22 P. 1 sp. 2 cp convert_from_copper (3242) 3242 copper pieces is: 64 gp Bsp. 2 cp 5.) This function requires a bit of preparation first: Try entering each of the following in a Python shell: print('Hobbit' 10) print('Hobbit' * 2) print('Hobbit' I) Using what you just learned, write a function called repeat word that has three parameters. The first is for a word (a string). The second is for an integer representing a number of rows. The third is for an integer representing a number of columns. The function prints the word in a number of rows equal to the value of the rows parameter and each row contains the word repeated a number of times equal to the columns parameter. 6.) Using what you learned in the previous question, write a function called text_triangle that takes an integer parameter and prints X's in a triangle shape. Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): text_triangle (3) XXX text_triangle (10) xx XXX xxxx xxxxx xxxxxx xxxxxxx xxxxxxxx xxxxxxxxx xxxxxxxxxx text_triangle (0) 7.) Write a function called surface area_of_cylinder that takes two arguments. The first is a float representing the radius of a cylinder. The second is a float representing the height of a cylinder. The function calculates and prints the surface area of a cylinder with the given radius and height. You will need to import the math module and use the math.pi constant. The formula is: SA-2 r 2nuh Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): surface area of cylinder (10.0, 10.0) The surface area of a cylinder with radius 10.0 and height 10.0 is 1256.6370614359173 surface area_of_cylinder (0.0, 1.0) The surface area of a cylinder with radius 0.0 and height 1.0 is 0.0 8.) The math module has a function called sort that returns the square root of its parameter. It is used like this: math.sart (100). Imagine you are flying a kite and the kite gets caught in the top of a perfectly straight palm tree, The string pulls free from the kite leaving you with the full length of string and your kite stuck in the tree. You measure the distance from you to the base of the tree. Given the length of the kite string and the distance from you to the base of the tree you can calculate the height of the tree using the Pythagorean Theorem: d'+b = c? In this case o is the distance from you to the tree, b is the unknown height of the tree, and is the length of the kite string, kite is here length of kite string height of tree? distance from you to tree con cob45306 Write a function called tree height that takes two arguments. The first is a float representing the distance from you to the base of the tree. The second is a float representing the length of the kite string. The function will calculate and print the height of the tree as shown in the examples below. The function will calculate and print the height of the tree. Here are some examples of calling the function with different arguments. The code executed is in blue, the output produced is in green): tree_height(300, 500) Kite string: 500 Distance: 300 Height: 400.0 tree_height(100, 141.421356) Kite string: 141.421356 Height: 99.99999966439368 + 7 18 tree_height(100, 141.421356) Kite string: 141.421356 Distance: 100 Height: 99.99999966439368 Since we are not using turtle graphics in this program, you will lose points if your main function still has this line (you don't actually need a main function for this assignment): turtle.getscreen().exitonclick() Verify that your documentation makes sense and that you've added documentation to each of your functions, per the examples in docstrings.py or any of the posted example code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions