0% found this document useful (0 votes)
2 views2 pages

r233703x Python Assignment

The document contains two programming tasks for a course in Educational Technology. The first task involves writing a program to check if a given string is a palindrome, while the second task focuses on implementing exception handling to calculate the factorial of a user-provided positive number. Both tasks include sample code and error handling mechanisms.

Uploaded by

matimbatarira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

r233703x Python Assignment

The document contains two programming tasks for a course in Educational Technology. The first task involves writing a program to check if a given string is a palindrome, while the second task focuses on implementing exception handling to calculate the factorial of a user-provided positive number. Both tasks include sample code and error handling mechanisms.

Uploaded by

matimbatarira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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}")

You might also like