Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSE101 Lab 8 Assignment Write the Python code of the following problems: Task 1 You are given a tuple with numbers. Your job is to

CSE101 Lab 8 Assignment

Write the Python code of the following problems:

Task 1

You are given a tuple with numbers. Your job is to finds the sum and average of the given numbers in that tuple. =================================================================== Example 1: Given tuple: (1, 18, 15, 12, 10, 25, 15, 18, 15, 18, 18, 20, 3, 34, 3) Output: The sum is: 225 The average is: 15.0 =================================================================== Example 2 Given tuple: (25, 18, 15, 12, 10, 25, 15, 10, 25, 5, 8, 8, 25) Output: The sum is: 201 The average is: 15.461538461538462 ===================================================================

In [ ]:

tup1 = (1, 18, 15, 12, 10, 25, 15, 18, 15, 18, 18, 20, 3, 34, 3) #tup2= (25, 18, 15, 12, 10, 25, 15, 10, 25, 5, 8, 8, 25) ### Write your code here ### ### End Code ###

Task 2

Assume, you have been given a tuple. movies = (\ ("Best Picture", "Nomadland", 7.4),\ ("Best Adapted Screenplay", "The Father", 8.3),\ ("Best Animated Feature Film", "Soul", 8.1),\ ("Best International Feature Film", "Another Round", 7.8)\ ) Write a Python program that prints the information about 93rd Academy Awards with the corresponding IMDb movie rating from a tuple. Your program should print the award category, movie name, and its ratings in the following way: =================================================================== 'Nomadland' won the 'Best Picture' category; IMDb Rating: 7.4/10\ 'The Father' won the 'Best Adapted Screenplay' category; IMDb Rating: 8.3/10\ 'Soul' won the 'Best Animated Feature Film' category; IMDb Rating: 8.1/10\ 'Another Round' won the 'Best International Feature Film' category; IMDb Rating: 7.8/10 =================================================================== Hint: You need to handle the quotation marks as a part of the output. [Must use Tuple unpacking before printing.] ===================================================================

In [ ]:

movies = ( ("Best Picture", "Nomadland", 7.4), ("Best Adapted Screenplay", "The Father", 8.3), ("Best Animated Feature Film", "Soul", 8.1), ("Best International Feature Film", "Another Round", 7.8) ) ### Write your code here ### ### End Code ###

Task 3

Suppose you are given two dictionaries.\ Now create a new dictionary "runs", merging the two dictionaries, so that the original two dictionaries remain unchanged. Note: You can not use any dictionary functions here. =================================================================== Given: {'Sakib':150, 'Tamim':80, 'Riad':109} {'Mushfiq':108, 'Liton': 14} Output: {'Sakib':150, 'Tamim':80, 'Riad':109, 'Mushfiq':108, 'Liton': 14} ===================================================================

In [ ]:

odi_run1={'Sakib':150, 'Tamim':80, 'Riad':109} odi_run2={'Mushfiq':108, 'Liton': 14} ### Write your code here ### ### End Code ###

Task 4

Suppose, you are working as the IT officer in a super shop named 'Raju Bazar'. One of your salesperson have the following two separate lists containing a few fruit names and the corresponding prices: list1 = ['Apple', 'Grape', 'Mango', 'Orange', 'Guava'] list2 = [200, 480, 80, 300, 110] You need to creates a dictionary where fruits names will be the key and the corresponding prices will be the values of that dictonary and the output dictionary will look as follows: {'Apple': 200, 'Grape': 480, 'Mango': 80, 'Orange': 300, 'Guava': 110} ===================================================================

In [ ]:

list1 = ['Apple', 'Grape', 'Mango', 'Orange', 'Guava'] list2 = [200, 480, 80, 300, 110] ### Write your code here ### ### End Code ###

Task 5

You are given a dictionary named Quiz_marks as given below. quiz_marks = {'Leonard': 18, 'Sheldon': 20, 'Raj': 19, 'Howard': 17, 'Penny': 10, 'Amy':20, 'Bernadette': 15} Your job is to make two different dictionaries called even_quiz_marks and odd_quiz_marks. In the even_quiz_marks dictionary only the people who got even marks in the quiz will be listed and in the odd_quiz_marks dictionary only the people who got odd marks in the quiz will be listed. The two dictionary will look as follows: even_quiz_marks = {'Leonard': 18, 'Sheldon': 20, 'Penny': 10, 'Amy':20} odd_quiz_marks = {'Raj': 19, 'Howard': 17, 'Bernadette': 15} ===================================================================

In [ ]:

quiz_marks = {'Leonard': 18, 'Sheldon': 20, 'Raj': 19, 'Howard': 17, 'Penny': 10, 'Amy':20, 'Bernadette': 15} # Write your code here: ### End Code ###

Task 6

Suppose, you are given the following tuple. tup1 = (12, 15, 6, 10) Write a Python program that replaces the first value with the multiplication of the rest of the values from the tuple. Finally, print the new tuple. Output: =================================================================== (900, 15, 6, 10) =================================================================== [As tuples are immutable, you need to create a new tuple to print the modified result. You are not allowed to use min().]

In [ ]:

tup1 = (12, 15, 6, 10) ### Write your code here ### ### End Code ###

Task 7

You are given the following dictionary where the keys are student names and the values are lists of marks they got in quizzes. marks = {'Alan': [14, 12, 13], 'Bob': ['15', '15'], "Dan": [14, 15, 16, 17]} Write a Python program that finds the average of the quiz marks for each student and make another dictionary with those average marks. The output dictionary will look like as given below: {'Alan': 13.0, 'Bob': 15.0, 'Dan': 15.5} ===================================================================

In [ ]:

marks = {'Alan': [14, 12, 13], 'Bob': ['15', '15'], "Dan": [14, 15, 16, 17]} ### Write your code here ### ### End Code ###

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions