Page 342 - Information_Practice_Fliipbook_Class11
P. 342
if num <= 3:
print(num)
elif num % 2 == 0 or num % 3 == 0:
continue
else:
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
break
i += 6
else:
print(num)
Program 5: Write a program to accept a number and print sum of following series:
1/1! + 2/2! + 3/3! + ... n/n!
Ans. n = int(input("Enter a number (n): "))
seriesSum = 0
factorial = 1 # Initialize the factorial to 1
for i in range(1, n + 1):
factorial *= i # Calculate the factorial incrementally
term = i / factorial
seriesSum += term
print(f"The sum of the series is: {seriesSum:.4f}")
Program 6: Write a program to check whether a number is a palindrome or not.
Ans. '''
Objective : To check whether a number is a palindrome
Input : num - numeric value
Output : Appropriate Message
'''
num = int(input("Enter a number: "))
n = num #storing the number for later usage
328 Touchpad Informatics Practices-XI

