Assignments 1 5.
Assignments 1 5.
print(f"{num1} is {check_sign(num1)}")
print(f"{num2} is {check_sign(num2)}")
OUTPUT:
Question 2: Write a program to perform operations on
list and tuples in python
Program:
# List num_list = [10, 20, 30, 40, 50]
print("Original List:", num_list)
num_list.append(60) # Adding an element
print("List after append:", num_list)
num_list.remove(20) # Removing an
element print("List after removing 20:",
num_list) num_list.reverse() # Reversing the
list print("Reversed List:", num_list)
print("Sum of List Elements:", sum(num_list))
OUTPUT:
Question Write a program to use operator and
conditional statement in python.
Question 3: Write a Program to perform operations on
set and dictionary.
Program:
num_set = {10, 20, 30, 40, 50}
print("Original Set:", num_set)
num_set.add(60)
print("Set after adding 60:", num_set)
num_set.remove(20)
print("Set after removing 20:", num_set)
num_set.discard(100)
print("Set after discarding 100:", num_set)
num_dict['b'] = 5
print("Dictionary after updating 'b':", num_dict)
key_to_find = 'c'
if key_to_find in num_dict:
print(f"Value for key '{key_to_find}':", num_dict[key_to_find]) else:
print(f"Key '{key_to_find}' not found in dictionary.")
OUTPUT:
Question Write a program to use operator and
conditional statement in python.
Question 4:Write a Program for function using different
types of arguments
Program:
def greet(name, age):
print(f"Hello {name}, you are {age} years old!")
def sum_numbers(*args):
total = sum(args)
print(f"The sum of the numbers is: {total}")
def person_details(**kwargs):
print("Person details:") for key,
value in kwargs.items():
print(f"{key}: {value}")
greet("Aboli", 15)
introduce("Pramod", 30)
introduce("KORALE", 35, "New York")
result = add(5)
print(f"Result of addition: {result}")
sum_numbers(1, 2, 3, 4, 5)
person_details(name="Korale", age=18, city="India",
occupation="Engineer")
OUTPUT:
Question Write a program to use operator and
conditional statement in python.
Question 5:Write a program to show the use of lambda
,reduce,map.
Program:
numbers = [1, 2, 3, 4, 5]
squared_numbers = list(map(lambda x: x ** 2, numbers))
print("Squared numbers using map and lambda:", squared_numbers)
sum_of_numbers = sum(numbers)
print("Sum of numbers using lambda:", sum_of_numbers)
OUTPUT: