62 540
Assignments Done
98,7%
Successfully Done
In June 2018

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
Expert's answer

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions