I want to write a code that ends when I enter the Python while door, how can I implement it?

Asked 1 years ago, Updated 1 years ago, 140 views

n = input('Enter the student's name and grade)\nExample) David 537548 :')
while n=='\n':
    n1,n2,n3,n4 = n.split()
    n2 = int(n2)
    n3 = int(n3)
    n4 = int(n4)
    L.append(n1)
    M.append([n2,n3,n4])
    Avg.append(int((n2+n3+n4)/3))
    if (n2+n3+n4)/3 >= 90:
        grade.append('A')
    elif (n2+n3+n4)/3 >= 80:
        grade.append('B')
    elif (n2+n3+n4)/3 >= 70:
        grade.append('C')
    else :
        grade.append('D')

I tried to make a code, but it didn't workㅜ<

while-loop python enter newline

2022-09-22 19:48

1 Answers

First of all, input should be in the repeat statement. Logicool

In addition, the input function is considered to have ended when the opening character (\n) is entered. Enter only the opening character to save an empty string.

The while statement ending with the enter input can be implemented as follows.

while True:
    n = input ('input:')
    if n == '':
        break;


2022-09-22 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.