Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+8 votes

How would you get your loop statement to repeat the radius and volume inputted by the user?

asked in CSC201 Spring 2021 by (8 points)

6 Answers

+5 votes
Best answer

You can set your input variable equal to the radius and then put your variable into the range+1, but then when you do you equation you want to use your "for" variable so that way the inputted radius will be supplemented into the loop. i.e
for i in range (1, rad+1):
then your equation in terms of i goes here.

answered by (798 points)
selected by
+5 votes

with a print statement inside the for loop.

for example,

for i in range(5)

would print

answered by (8 points)
+4 votes

There is a hint mentioned in the description that there are 7 spaces between the radius number and the volume.

So you can use the loop to print the output of radius and volume like

for i in range(1,variable+1):

If you apply that loop form into question 5, you just create print() with 7 spaces (' ') between the radius variable and volume variable and with sep="" if there are any comma:

for radius in range(1, inputrad+1)
     print(radius, '       ', volume, sep="")

Hope this helps!

answered by (244 points)
+4 votes

Suppose that n is the input variable.

First, find the range for the loop. As stated in the problem, you will have to print the radius and volume n times. Hence, you will get the range (1,n+1).
for r in range (1,n+1):

Note: The variable r is equal to the radius. Therefore, if you want to print the radius, print r.

Second, find the calculation for the volume and put it in the loop.

The final step is the print statement, make sure to put it in the loop.

answered by (390 points)
edited by
+1 vote

Let us consider a is your input variable. So, for the loop just add -

for i in range(1,a+1):


And it would give you the output -

answered by (8 points)
+1 vote

I know everyone answered the same answer but in simple words it's just:

For hi in range(1,Yourvariable+1):

print(radius, '           ', volume, sep="")

which would repeat the variables because it is in the for loop!!!

I know its the same answer but gotta get some points!!!!

answered by (8 points)