0% found this document useful (0 votes)
20 views4 pages

Python

Uploaded by

dealerweed37
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)
20 views4 pages

Python

Uploaded by

dealerweed37
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

Python

Experiment 6

Jagrat mohan mehta

590022800

B24

1. Scan n values in range 0-3 and print the number of times each value has occurred.
Code: n = int(input())

values = list(map(int, input().split()))

count = {0:0, 1:0, 2:0, 3:0}

for v in values:
if v in count:
count[v] += 1

for k in range(4):
print(k, ":", count[k])

2. Create a tuple to store n numeric values and find average of all values.
3. n = int(input())
4. t = tuple(map(int, input().split()))
5.
6. for i in t:
7. total += i
8.
9. print(total / n)

3. WAP to input a list of scores for N students in a list data type. Find the score of the runner-up and print the output.
Sample Input
N=5
Scores= 2 3 6 6 5
Sample output
5
Note: Given list is [2, 3, 6, 6, 5]. The maximum score is 6, second maximum is 5. Hence, we print 5 as the runner-up score.
n = int(input())
scores = list(map(int, input().split()))

max_score = max(scores)
scores = [x for x in scores if x != max_score]

runner_up = max(scores)
print(runner_up)

4. Create a dictionary of n persons where key is name and value is city.


a) Display all names
b) Display all city names
c) Display student name and city of all students.
d) Count number of students in each city.
n = int(input())
d = {}

for _ in range(n):
name = input()
city = input()
d[name] = city

print(list([Link]()))
print(list([Link]()))

for k, v in [Link]():
print(k, v)

city_count = {}
for city in [Link]():
city_count[city] = city_count.get(city, 0) + 1

print(city_count)

5. Store details of n movies in a dictionary by taking input from the user. Each movie must store details like name, year, director
name,
production cost, collection made (earning) & perform the following :-
a) print all movie details
b) display name of movies released before 2015
c) print movies that made a profit.
d) print movies directed by a particular director.
n = int(input())
movies = []

for _ in range(n):
name = input()
year = int(input())
director = input()
cost = float(input())
collection = float(input())

[Link]({
"name": name,
"year": year,
"director": director,
"cost": cost,
"collection": collection
})

for m in movies:
print(m)

for m in movies:
if m["year"] < 2015:
print(m["name"])

for m in movies:
if m["collection"] > m["cost"]:
print(m["name"])

d_name = input()
for m in movies:
if m["director"] == d_name:
print(m["name"])

6. Create a contact book where users can store, search, update, and delete contacts. Use dictionary for storing contacts.
contacts = {}

while True:
print("[Link] [Link] [Link] [Link] [Link]")
ch = int(input())

if ch == 1:
name = input()
phone = input()
contacts[name] = phone

elif ch == 2:
name = input()
print([Link](name, "Not found"))

elif ch == 3:
name = input()
phone = input()
contacts[name] = phone

elif ch == 4:
name = input()
[Link](name, None)

elif ch == 5:
break

7. Create a Todo list Manager where users can add, view, and remove tasks. Use List for storing tasks.

tasks = []

while True:
print("[Link] [Link] [Link] [Link]")
ch = int(input())

if ch == 1:
task = input()
[Link](task)

elif ch == 2:
for t in tasks:
print(t)

elif ch == 3:
task = input()
if task in tasks:
[Link](task)

elif ch == 4:
break

You might also like