Practical
Practical
Practical
Proposed practicals
Practical Create a program that asks the user to enter their name and their age. Print out a
No. 1 message addressed to them that tells them the year that they will turn 100 years old.
copy = n
#sum initially 0
s=0
while n!=0:
last_digit = n % 10
# ** operator is use to find power
s = s + (last_digit ** 3)
n = n // 10
if s==copy:
return True
else:
return False
def isPalindrome(s):
rev = s[::-1]
if rev==s:
return True
else:
return False
def main():
#input number to check armstrong number
n = int(input("Enter number to check armstrong : "))
if isArmstrong(n):
print("%d is Armstrong number" % n)
else:
print("%d is not Armstrong number" % n)
if isPalindrome(s):
print("%s is Palindrome" % s)
else:
print("%s is not Palindrome" % s)
main()
Practical Write a recursive function to print the factorial for a given number
No. 6
Solution: def recur_factorial(n):
"""Function to return the factorial
of a number using recursion"""
if n == 1:
return n
else:
return n*recur_factorial(n-1)
Practical Write a Python script to sort (ascending and descending) a dictionary by value
No. 12
Solution: d={'A':100,'B':540,'C':239}
print("Total sum of values in the dictionary:")
print(sum(d.values()))