Reputation: 159
I am trying to write a program where a user enters a bunch of numbers and when 0 is entered the program ends and prints how many positive numbers were entered. I am fairly close to solving this but can't get the positive sum to print. Could you please explain where I have gone wrong?
Thanks in advance.
Please see attached my code.
userInput = None
oddNum = 0
evenNum = 0
while(userInput != 0):
userInput = int(input("Enter a number: "))
if(userInput > 0):
if(userInput % 2 == 0):
evenNum += 1
elif(userInput % 2 != 0):
oddNum += 1
print("positive numbers were entered".format(evenNum, userInput))
Upvotes: 0
Views: 323
Reputation: 1194
You are missing some of the required syntax for the string.format()
command.
For each variable you want injected into the string to be printed, you must include a pair of curly braces {}
. Otherwise, the arguments you pass to string.format()
are just ignored.
userInput = None
oddNum = 0
evenNum = 0
while(userInput != 0):
userInput = int(input("Enter a number: "))
if(userInput > 0):
if(userInput % 2 == 0):
evenNum += 1
elif(userInput % 2 != 0):
oddNum += 1
print("positive numbers were entered; {} even numbers, and {} odd numbers".format(evenNum, userInput))
Upvotes: 1