Answer the question
In order to leave comments, you need to log in
How to repeat the cycle if necessary?
There is a loop that must be repeated a certain number of times (variable much)
After its execution, it will ask whether it needs to be repeated the same number of times or not. If yes, the cycle repeats.
I tried like this, it didn’t work, it looks like the variable in the loop cannot be changed in the process
much = int(input('how much? '))
for i in range(much):
print('Privet')
if i == much-1:
more = str(input('Еще? '))
if more == 'yes':
much = much + much
else:
break
Answer the question
In order to leave comments, you need to log in
s-switch(@switch="switch")
this.switch
.
def loop(n):
for i in range(n):
print('Privet')
much = int(input('how much? '))
loop(much)
more = str(input('Еще? '))
if more == 'yes':
loop(much)
range()
, but it is better to get by with a variable that is reduced from much
to 0:much = int(input('how much? '))
i = much
while i > 0:
print('Privet')
i = i - 1
if i == 0:
more = str(input('Еще? '))
if more == 'yes':
i = much
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question