Question #194480

1. Write a program that reads an integer from the user. Then your program should display a message indicating whether the integer is even or odd.


2. A string is a palindrome if it is identical forward and backward. For example “anna”, “civic”, “level” and“hannah” are all examples of palindromic words. Write a program that reads a string from the user and uses a loop to determines whether or not it is a palindrome. 


Expert's answer

1.

n = int(input('Enter an integer: '))
print('The number', n, 'is', end=' ')
if n%2 == 0:
    print('even')
else:
    print('odd')

2.

word = input('Enter a word: ')

n = len(word)
m = n//2
print('The word "', word, '" is ', sep='', end='')
for i in range(m):
    if word[i] != word[-1-i]:
        print('not ', end='')
        break
print('a palindrome')
LATEST TUTORIALS
APPROVED BY CLIENTS