0% found this document useful (0 votes)
6 views5 pages

Python Programming Assignment Solutions

The document contains an assignment for a BCA course on Python programming, submitted by Ojas Sharma. It includes four programming tasks: calculating minimum, maximum, and average of three numbers; creating a list of distinct elements; generating squares of numbers from 1 to 30; and performing set operations like union, symmetric difference, and difference. Each task is accompanied by Python code and expected outputs.

Uploaded by

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

Python Programming Assignment Solutions

The document contains an assignment for a BCA course on Python programming, submitted by Ojas Sharma. It includes four programming tasks: calculating minimum, maximum, and average of three numbers; creating a list of distinct elements; generating squares of numbers from 1 to 30; and performing set operations like union, symmetric difference, and difference. Each task is accompanied by Python code and expected outputs.

Uploaded by

moonknightpluto
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASSIGNMENT

Course: BCA
Subject: Python
Submitted by:
Ojas Sharma (A25304824018)
Sem: 3rd
Amity School of Engineering and
Technology

Assignment Questions:
Programming with Python

1. Write a program in Python to create a function


that accepts three numbers and returns, minimum,
maximum and average of three numbers.

def min_max_avg(a, b, c):


minimum = min(a, b, c)
maximum = max(a, b, c)
average = (a + b + c) / 3
return minimum, maximum, average

a = int(input(“Enter first number: “));


b = int(input(“Enter second number: “));
c = int(input(“Enter third number: “));
result = min_max_avg(a, b, c)
print("Minimum:", result[0])
print("Maximum:", result[1])
print("Average:", result[2])

OUTPUT:

2. Write a Python function that takes a list and returns


a new list with distinct elements from the first list.

def distinct_elements(mylist):
return list(set(mylist))
original_list = [1, 2, 2, 2, 2, 3, 4, 5, 5]
distinct_list = distinct_elements(original_list)
print("Original List:", original_list)
print("Distinct Elements:", distinct_list)

OUTPUT:

[Link] a Python function to create and print a list


where the values are the squares of numbers
between 1 and 30.

def squareList():
square = [x ** 2 for x in range(1, 31)]
print("Squares from 1 to 30:", square)
return square

result = squareList()
OUTPUT:

4. Write a program in Python to create:


a) Union of sets,
b) Symmetric difference of sets,
c) Difference of sets.

def union_sets(set1, set2):


return set1 | set2

def symmetric_difference_sets(set1, set2):


return set1 ^ set2

def difference_sets(set1, set2):


return set1 - set2
A = {2, 4, 6, 8}
B = {6, 8, 10, 12}

print("Set A:", A)
print("Set B:", B)
print("Union:", union_sets(A, B))
print("Symmetric Difference:", symmetric_difference_sets(A,
B))
print("Difference (A - B):", difference_sets(A, B))

OUTPUT:

You might also like