# I am a network and security engineer and now decided to join a computer science program and i know very little about python am currently watching tutorial on python online but i will need help guys...can anyone help me with this questions

The volume of a sphere is 4/3πr3, where π has the value of “pi” given in Section 2.1 of your textbook. Write a function called print_volume ® that takes an argument for the radius of the sphere, and prints the volume of the sphere.

Call your print_volume function three times with different values for radius.

Include all of the following in your Learning Journal:

• The code for your print_volume function.
• The inputs and outputs to three calls of your print_volume.

Part 2

Write your own function that illustrates a feature that you learned in this unit. The function must take at least one argument. The function should be your own creation, not copied from any other source. Do not copy a function from your textbook or the Internet.

Include all of the following in your Learning Journal:

• The code for the function that you invented.

• The inputs and outputs to three calls of your invented function.

• A description of what feature(s) your function illustrates.

``````def print_volume(radius):
volume = 0
volume = radius **3 #This make the radius cubed
volume *= 4/3
return volume

#While this can be reduced to fewer lines, I wrote it out so that you can see my logic.

``````

Side note: The 4/3 may produce a floating point error which use can avoid by importing Decimal from decimal (a module) and wrapping the 4/3 in the Decimal call function ( Decimal(‘4/3’) )

1 Like

thanks bro i appreciate

1 Like

Excellent advice to be aware of floating point errors. With a single calculation, you are pretty much guaranteed 16-digit precision. However, with multiple calculations, especially if they are chained, you can indeed get into trouble.

3 Likes

thanks you very much

This looks like a homework question.
" What is Codecademy’s Integrity Policy?

We do not, under any circumstances, tolerate cheating or dishonesty. Please do not post answers, or ask for them."

2 Likes

Thanks, @gloriosa, for that advice. Codecademy is offered as a learning environment, and not as a resource for copying answers.

In fact, the function provided by @diegozavala573741513 is incorrect. Perhaps, @bit0980598846, you can convert this into a learning opportunity by figuring out what is wrong with that solution and letting us know what you find out.

3 Likes

Oh yeah, I completely forgot to multiply by pi. Also, im new to the discussion board, so how would I go about answering a question without really “answering” the question?

1 Like

Have a read of the forums a bit more, you’ll see how several others here go about nudging people towards the solution without outright writing the code for them.

A few examples, though: you could point out an error, say a typo in a function definition, without being specific or correcting it; or, if a poster is struggling to grasp the algorithmic concept they need to code, you could walk them through the steps in writing (i.e. sentences, not code blocks) and then let them code it…

Everyone’s different though! You’ll figure out your own way of conveying how to solve a problem without actually solving the problem after a little while.

Also, kudos for helping out - even if you did do all the work for them.

3 Likes

The advice from @thepitycoder, above, is excellent. Begin with this:

As you browse through the Forums, think about what advice that you find there seems most helpful.

In a case such as the current one, where the original poster has not shown us any code at all, and is asking for help, we often begin by asking them to post what they have done thus far. Then we can proceed by asking pointed questions designed to call their attention to what they have not yet gotten right.

During the discussion, we can also provide them with examples of code that have some similarities to, but are not identical to the solution that they are attempting to achieve.

If someone posts code that is not formatted, and therefore does not exhibit indentation and other important details, advise them to visit How to ask good questions (and get good answers).

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.