Answer to Question #20933 in Python for Andre

Question #20933
Write a program that repeatedly asks a user to enter a number. Terminate the program when the user enters -1. The program should display the number of even and odd numbers entered by the user. (Exclude -1)

Sample:
Enter a number: 4
Enter a number: 7
Enter a number: 2
Enter a number: 8
Enter a number: -1
Number of even number: 3
Number of odd number: 1
1
Expert's answer
2012-12-24T10:59:19-0500

odd = 0
even = 0

while True:
num = int(input("Enter a number: "))

if num == -1:
break;
elif num%2==0:
even += 1
else:
odd += 1


print ("Number of even number: "+str(even))
print ("Number of odd number: "+str(odd))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS