Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+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 (1 point)

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 (1 point)
selected by
+5 votes

with a print statement inside the for loop.

for example,

for i in range(5)
     print(i)

would print

1
2
3
4
5
answered by (1 point)
+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):
     print('word')

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:
ex:

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

Hope this helps!

answered by (1 point)
+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).
example:
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 (1 point)
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):

 print(a)

And it would give you the output -
1
2
3
4
5

answered by (1 point)
+1 vote

Hi,
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 (1 point)
...