Python repeat question

Asked 2 years ago, Updated 2 years ago, 19 views

How can I input up to 5 pieces of data using a range, for, etc.?

python

2022-09-20 22:29

1 Answers

You're wondering what it means to write a repeat and get up to five pieces of data?

This means that the task of receiving data should be + repeated + up to 5 times.

It's like a pun, but there's an important difference. Basically, what you have to do is take an input, which means that it has to be repeated, up to five iterations.

Do you understand? Please don't move on until this is understood.)

What do you do with a maximum of 5 iterations?

There are two ways. The first method is:

The second method is:

Do you understand that? (If not, please don't go down.)

How do we implement method number one? In Python, infinite iterations are implemented as while.

inputs = []
inTheLoop = True

while inTheLoop :
    nput = input('). Type "Stop" and you'll stop. You can enter up to five.')
    ifput == 'Stop':
        inTheLoop = False
    else :
        inputs.append(nput)
        inTheLoop = len(inputs) < 5

print(inputs)

How do we implement method number two? In Python, finite iterations are assumed to be for.

inputs = []

for x in range(1, 5) :
    nput = input('input'! Type "Stop" and you'll stop! You can only enter up to 5!')
    ifput == 'Stop':
        break
    else :
        inputs.append(nput)

print(inputs)

Try running the sauce, try fixing it like this, and try studying it.


2022-09-20 22:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.