+ 1
Write a python program which will ask user to enter positive integer. Your program will output a message that indicates if this number is an even or odd number for example- if user enter 5 your program can output a message like"number 5 is an odd number"
4 Antworten
+ 2
a = int(input("Enter a positive integer: "))
if a % 2 == 0:
print("number {0} is an even number".format(a))
else:
print("number {0} is an odd number".format(a))
+ 1
print("Insert a value:")
number = int(input())
if number % 2 == 0:
print(number, "is an even number")
else:
print(number, "is an odd number")
+ 1
The two programs written are correct, but just to add a little extra, if you want to make sure the number is positive:
number = -1
while number<0:
try: #in case the user inputs a word or a float
number=int(input ("please put a positive integer: "))
except:
pass
after that you just use any of the two other programs in the comments to get the result
0
i = int(raw_input("> "))
if i % 2 == 0:
print (i, "is even")
else:
print (i, "is odd")
# simplest program