0% found this document useful (0 votes)
2 views9 pages

Assignments 1 5.

The document contains programming exercises in Python covering various topics such as operators, conditional statements, lists, tuples, sets, dictionaries, functions with different argument types, and the use of lambda, reduce, and map. Each section includes code snippets demonstrating the implementation of these concepts. The exercises are designed for a student named Korale Aboli Pramod with enrollment number 2306099.

Uploaded by

shrutimanval104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Assignments 1 5.

The document contains programming exercises in Python covering various topics such as operators, conditional statements, lists, tuples, sets, dictionaries, functions with different argument types, and the use of lambda, reduce, and map. Each section includes code snippets demonstrating the implementation of these concepts. The exercises are designed for a student named Korale Aboli Pramod with enrollment number 2306099.

Uploaded by

shrutimanval104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SLA

Name:Korale Aboli Pramod


Enroll No:2306099
Div:H2

Question 1: Write a program to use operator and


conditional statement in python.
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

print("Sum:", num1 + num2)


print("Difference:", num1 - num2) print("Product:", num1 *
num2) print("Quotient:", num1 / num2 if num2 != 0 else
"Undefined") print("Modulus:", num1 % num2 if num2 != 0 else
"Undefined") print("Exponentiation:", num1 ** num2)

if num1 > num2: print("First


number is greater.") elif num1 <
num2: print("Second number is
greater.") else: print("Both
numbers are equal.")

print(f"{num1} is", "Even" if num1 % 2 == 0 else "Odd")


print(f"{num2} is", "Even" if num2 % 2 == 0 else "Odd")

def check_sign(num): return "Positive" if num > 0 else "Negative"


if num < 0 else "Zero"

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))

# Tuple num_tuple = (5, 15, 25, 35, 45)


print("\nOriginal Tuple:", num_tuple) print("Length
of Tuple:", len(num_tuple)) print("Maximum Value
in Tuple:", max(num_tuple)) print("Minimum Value
in Tuple:", min(num_tuple)) print("Index of 25 in
Tuple:", num_tuple.index(25))

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_set2 = {30, 40, 50, 60, 70}


print("Union of sets:", num_set.union(num_set2)) print("Intersection
of sets:", num_set.intersection(num_set2)) print("Difference of
sets:", num_set.difference(num_set2))

num_dict = {'a': 1, 'b': 2, 'c': 3}


print("\nOriginal Dictionary:", num_dict)

print("Dictionary after adding a new pair:", num_dict)

num_dict['b'] = 5
print("Dictionary after updating 'b':", num_dict)

del num_dict['a'] print("Dictionary after


removing 'a':", 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 introduce(name, age, city="Unknown"):


print(f"My name is {name}, I am {age} years old, and I live in {city}.")

def add(a, b=10):


return a + b

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)

even_numbers = list(filter(lambda x: x % 2 == 0, numbers))


print("Even numbers using filter and lambda:", even_numbers)

average_of_numbers = sum(numbers) / len(numbers) print("Average


of numbers:", average_of_numbers)

OUTPUT:

You might also like