FACULT OF EDUCATION
DEPARTMENT OF EDUCATIONAL TECHNOLOGY
NAMES: NDAGURWA LIZZY R233703X
PROGRAMME: BED-ICT 312
LECTURER NAME: DR GAVAI P
Question 1
Write a program that assigns a string to a variable and checks if its a palindrome.
string=input('Enter a string:')
reversestring=(string[::-1])
if reversestring==string:
print('palindrome')
else:
print('Not palindrome')
Question 2
Write a program impementing exception handling that calculates the factorial of a number. The
program should ask the user for a number and print the factorial to the console.
def factorial (n):
if n==0 or n==1:
return 1
return n * factorial (n-1)
try:
num=int(input("Enter a positive number:"))
if num<0:
print("Error:Please enter a positive number")
else:
result=factorial(num)
print(f"(Factorial of (num) is: {result}")
except ValueError as e:
print (f"Error: is {e}")
except ValueError as e:
print(f"An unexpected error occured: {e}")