Professional Documents
Culture Documents
VS
VS
VS
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q.1 : Write a python program to check if a value entered by ther user is palindrome or not.
CODE:-
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev-rev*10+dig
n=n//10
if(temp==rev):
else:
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q.2 : write a python program to check if a value entred by the user is armstrong or not.
"))
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q.3 : cosider a number entred by user. Now calculate the factorial of this number in
python. CODE :-
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q.4 : write a python program to print the fibonacci sequence upto the range entred by the
user.
CODE:-
n1, n2 = 0, 1 count = 0
if nterms <= 0:
print("Please enter a positive integer") elif nterms
== 1: print("Fibonacci sequence upto",nterms,":")
print(n1) else: print("Fibonacci sequence:") while
count < nterms:
print(n1) nth = n1
+ n2 # update values
n1 = n2 n2 = nth
count += 1
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q.5 : write a python program to check wheter the number entred by the user is a perfect
number or not.
CODE:-
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q6. 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).
CODE:
def replace_spaces_with_tabs(text):
return text.replace(" ", " ")
long_string = "This is an example string that we will use to replace spaces with tabs."
print(long_string)
result = replace_spaces_with_tabs(long_string)
print(result)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q7. Take any list and print it in the following manner:
a) Print only last 3 elements
b) Print all values except first and last value
c) Print only first 3 elements
CODE:
sample_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(sample_list)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q8. Python program to remove duplicate values from a list.
CODE:
def remove_duplicates(input_list):
return list(set(input_list))
sample_list = [1, 2, 2, 3, 4, 4, 5]
print("original list:",sample_list)
unique_list = remove_duplicates(sample_list)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q9. Consider a tuple having values integer, decimal and string. Write a python program to
delete all decimal values and add 3 character values in it.
CODE:
non_decimal_values = []
non_decimal_values.append(item)
new_tuple = tuple(non_decimal_values)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q10. Make a dictionary in which keys are in numbers and values are cube of that key.
CODE:
numbers = [1, 2, 3, 4, 5]
cube_dict = {}
cube_dict[number] = number ** 3
cube_dict.clear()
print("Dictionary after emptying:", cube_dict)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q11. Write a python program having a user defined function which will calculate the
total number of vowels used in string entered by a user.
CODE:
def count_vowels(input_string):
vowels = 'aeiouAEIOU'
vowel_count = 0
if char in vowels:
vowel_count += 1
return vowel_count
total_vowels = count_vowels(user_input)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q12. A shop will give discount of 10% if the cost of purchased quantity is more than 1000
rupees. Now write a python program having a user defined function which will first
calculate whether a user purchased quantities more than 1000 rupees or not and then
accordingly it will print the total cost for user.
CODE:
def calculate_discount(total_cost):
if total_cost > 1000:
discount = total_cost * 0.10
discounted_price = total_cost - discount
return discounted_price, discount
else:
print(“discount is not applicable”)
total_cost = float(input("Enter the total cost of purchased quantities (in rupees): "))
final_cost, discount_given = calculate_discount(total_cost)
if discount_given > 0:
print(f"You have received a discount of {discount_given} rupees.")
else:
print("No discount applied.")
print(f"The final cost after discount is: {final_cost} rupees.")
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q13. Suppose a company decided to give bonus of 5% to their employee if his/her year of
service in the company is more than 5 years. Now write a python program having a user
defined function which will print the net bonus amount. Ask user to input the salary and the
year of service.
CODE: def calculate_bonus(salary, years_of_service):
if years_of_service > 5:
else:
bonus = 0
return bonus
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q14. Write a lambda function in python which will multiplies two values (i.e. x*y). Now
using this function write a python program to print the table of a number (from 1 to 10)
entered by a user.
CODE:
multiply = lambda x, y: x * y
result = multiply(number, i)
OUTPUT:
NAME: AMAN SUYAL
ROLL NO: 10
SECTION: E2
SUBJECT: PBC 401
Q15. Write a Python program to square and cube every number in a given list of integers
using Lambda.
CODE:
numbers = [1, 2, 3, 4, 5]
square = lambda x: x ** 2
cube = lambda x: x ** 3
squared_numbers = list(map(square, numbers))
cubed_numbers = list(map(cube, numbers))
print("Original numbers:", numbers)
print("Squared numbers:", squared_numbers)
print("Cubed numbers:", cubed_numbers)
OUTPUT: