Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

loops - What does 'n' mean in this program (python)?

In the sample program below, I tried to find the even number with the the number I typed in (2, 1, 4, 0) these 4 numbers. The result is 2, but I don't know what (n) means in this program.

a = int(input())

n = 0

while a != 0:
    if a % 2 == 0:
        n = n + 1
    a = int(input())

print(n)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

here n is used to count even numbers.

the loop will keep checking whether given input is 0 or not if it is 0 the loop will exit if not it will check whether it is even or odd, if the number is even it will increase the value of n by 1. If you input 10 even numbers the value of n will be 10 respectively.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...