I'd like to get out of Python's double-repeated door. Give me wings.

Asked 2 years ago, Updated 2 years ago, 21 views

new_score = []

N = int(input())

breaker = False

whileTrue: #Enter again if incorrectly

    score = list(map(int, input().split())) 

    if len(score) == N:
        for s in score:
            if s <= 0 or s > 100:
                print("Score Error: Re-entering")
                continue
            elif 100 >= s > 0:
                breaker = True
                break

    elif breaker == True:
        break

    else:
        print ("Score Exceeded: Re-entered
        continue

for i in score:

    new_score.append(i/max(score) * 100)

print(new_score)

This is a double repeat statement that is re-entered when the score is incorrectly entered (greater than 100 and less than 0). If it's entered correctly (less than 100), it doesn't go out of the while statement. Help me. Please let me know if there is any other way to express the code more concisely.

python

2022-09-22 18:31

1 Answers

new_score = []
N = int(input())
whileTrue: #Enter again if incorrectly
    breaker = True
    score = list(map(int, input().split())) 
    if len(score) == N:
        for s in score:
            if s <= 0 or s > 100:
                print("Score Error: Re-entering")
                breaker = False
                break;
        if breaker == True:
            break
    else:
        print ("Score Exceeded: Re-entered
        continue
for i in score:
    new_score.append(i/max(score) * 100)
print(new_score)

I don't quite understand the meaning of the problem, but this should be accurate.


2022-09-22 18:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.