+ 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"

28th Jan 2017, 2:36 AM
Parita Shah
Parita Shah - avatar
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))
28th Jan 2017, 2:47 AM
Samuel Neo
Samuel Neo - avatar
+ 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")
28th Jan 2017, 2:47 AM
Dawzy
Dawzy - avatar
+ 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
28th Jan 2017, 8:45 AM
ramzi
ramzi - avatar
0
i = int(raw_input("> ")) if i % 2 == 0: print (i, "is even") else: print (i, "is odd") # simplest program
30th Jan 2017, 2:52 AM
admani1010