Assignment
Assignment
value = str(value)
if value == value[::-1]:
print(f"{value} is a palindrome.")
else:
is_palindrome(value)
number = int(number)
if number == sum_of_cubes:
else:
is_armstrong(number)=
3. Consider a number entered by a user. Now calculate the Factorial of
this number
Ans
def factorial(n):
n = int(n)
fact = 1
fact *= i
return fact
n = int(n)
a, b = 0, 1
sequence = []
while a < n:
sequence.append(a)
a, b = b, a + b
return sequence
print("Fibonacci:", fibonacci_(number))
5. Write a python program to check whether the number entered by the
user is a Perfect number or not.
Ans.
def is_perfect_number(n):
n = int(n)
if sum(divisors) == n:
else:
is_perfect_number(number)
6. Consider any long string. Now replace each space between two words
with the tab (i.e. the space created when you press the key 'Tab' from
your keyboard).
Ans.
def replace_spaces_with_tabs(string):
print(replace_spaces_with_tabs(input_string))
return list(set(my_list))
10.Make a dictionary in which keys are in numbers and values are cubes
of that key.
a) Print this dictionary
b) Print only its value
c) Now first empty that dictionary than again print it.
Ans.
cube_dict = {x: x**3 for x in range(1, 6)}
print("Dictionary:", cube_dict)
print("Values:", list(cube_dict.values()))
cube_dict.clear()