Python3 - How to stop asking for a certain number?

Asked

Viewed 31 times

-1

I know that for the present code it is necessary to use a repeating structure, and it can be while one of these. But I couldn’t link such a command to my code.

In order to facilitate understanding, I leave the question here:

A program that asks the user for multiple numbers and displays whether he is even or odd. The program stops asking for a number when the user type 0.

Code did:

print() #Espaço1
print('Digite apenas números ')
print() #E2
numpar = 0
numimpar = 0
while True:
numero = int(input('Digite o número: '))
for i in while():
    if numero % 2 == 0:
        numpar += 1
    else:
        numimpar += 1
print(f'Pares {numpar}')
print(f'Impares {numimpar}')

1 answer

3

Changing your program a little we would have:

print()
print('Digite apenas números ')
print()

numero = int(input('Digite o número: '))

while numero != 0:
    if numero % 2 == 0:
        print(f'o número {numero} é par')
    else:
        print(f'o número {numero} é impar')
    print()
    numero = int(input('Digite o número: '))

Remember that the command while is followed by a condition

I hope it helps

Browser other questions tagged

You are not signed in. Login or sign up in order to post.