Yesterday I posted a question where I was looking for a way to make an endless loop without using at all (because my teacher therefore wants, and also, we cannot use any commands that we did not see in the class). This was tricky because there was apparently not a very viable option that didn't use any other features like either .append, etc. for
while
while
itertools
You can see this question here.
Also, thank you very much for the feedback you guys brought me! :)
But I managed to talk with my teacher, and we got permission to use, itertools
or just a range, large enough (and not actually endless).
I have decided a few exercises already, but now I have the following instructions:
(Think of classes )
• Ask the user for a number (through the inputs) and keep asking until the user tells you to stop.
• Then calculate the average of all the numbers entered.
(This is actually a bit more complicated, but I cut it down and I think I can handle the rest)
As I said, I have to use a loop for
, but I cannot use whiles
at all.
while, - :
def grades():
totalg = 0
countg = 0
keepAdding = "y"
while(keepAdding == "y"):
qualif = int(input("Insert grades obtained, in scale from 0 to 100 "))
totalg = totalg + qualif
countg = countg + 1
keepAdding = str(input("Do you wish to keep adding data? (y/n) "))
print("The average of your grades is", totalg/countg)
- , for
? , .
, "" , break
.
! !:)