0% found this document useful (0 votes)
29 views

Assignment Lab

The document contains 7 programming tasks involving Python concepts like lists, dictionaries, random numbers, filtering, mapping and comprehension. The tasks include generating access codes, squaring even numbers in a range, tracking conference attendance, manipulating lists, filtering palindromes, finding duplicates in random numbers, averaging heights in dictionaries and converting temperatures.

Uploaded by

faiyaz ahmed
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)
29 views

Assignment Lab

The document contains 7 programming tasks involving Python concepts like lists, dictionaries, random numbers, filtering, mapping and comprehension. The tasks include generating access codes, squaring even numbers in a range, tracking conference attendance, manipulating lists, filtering palindromes, finding duplicates in random numbers, averaging heights in dictionaries and converting temperatures.

Uploaded by

faiyaz ahmed
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
You are on page 1/ 2

Assignment

CSE222
1. Scenario:
Agent Orion, an elite operative of the Galactic Reconnaissance Unit (GRU), has been tasked
with gathering intelligence on a secret facility operated by a rogue faction within the galaxy. To
infiltrate the facility undetected, Agent Orion needs to create a list of access codes based on a
specific pattern observed in the security system. Each access code consists of a combination of
alphanumeric characters, where the first character is a letter and the remaining characters are
digits. Agent Orion must generate these access codes using a Python program.
Task:
Create a Python program to assist Agent Orion in generating the access codes based on the
observed pattern. The program should take the following inputs:
An integer 'n', indicating the number of access codes to generate.
An integer 'm', indicating the length of each access code (excluding the first letter).
Output:
The program should output a list of 'n' access codes generated according to the observed pattern.
##hints## by importing random and string classes

2. Scenario: In a distant galaxy, Agent Vega, an expert code breaker within the Intergalactic
Security Bureau (ISB), is investigating encrypted transmissions from a hostile alien faction. To
analyze the data efficiently, Agent Vega needs to generate a list of squares of even numbers
found within a specific range. However, manually squaring each even number is time-
consuming, so she decides to create a Python program to automate this process using list
comprehension.
Task: Create a Python program to assist Agent Vega in generating a list of squares of even
numbers within a given range. The program should take the following input:
Two integers 'start' and 'end', representing the range of numbers (inclusive).
Output: The program should output a list containing the squares of even numbers within the
specified range, using list comprehension.

3. You are managing attendance for a conference and need to keep track of the attendees. Each
attendee has a unique attendee ID, and you need to create a mapping of attendee IDs to their
attendance status (either 'Attended' or 'Did not attend'). Write a Python program that takes the
total number of attendees and the IDs of attendees who attended the conference, and returns a
dictionary mapping each attendee ID to their attendance status for a particular day. Additionally,
print the dictionary and also create and print the total number of attendees who attended and did
not attend the conference.
Input:
The first line of input contains an integer n, the total number of attendees.
The second line of input contains n space-separated integers, representing the attendee IDs.
The third line of input contains an integer m, the total number of attendees who attended the
conference.
The fourth line of input contains m space-separated integers, representing the IDs of attendees
who attended the conference.
Output:
Print the dictionary mapping each attendee ID to their attendance status.
Print a dictionary containing the total number of attendees who attended and did not attend the
conference.
Example:
Input:
6
1001 1002 1003 1004 1005 1006
4
1002 1003 1005 1006
Output:
{1001: 'Did not attend', 1002: 'Attended', 1003: 'Attended', 1004: 'Did not attend', 1005:
'Attended', 1006: 'Attended'}
{'Attended': 4, 'Did not attend': 2}

4. You have the following list lst = ['1', '2', '3', '4', '5']. Using list comprehension generate the
following output. [('1', 1), ('2', 4), ('3', 9), ('4', 16), ('5', 25)]

5. Create a list of integers from 0 to 100. Filter out the palindrome numbers from the list using
the filter function.

6. Generate a list of 50 random numbers using random.randint(0, 100) .Find out the duplicate
numbers from the list. [Hint: use set and list’s remove() function to do it. Also, make sure to use
‘import random’]
7. You have a dictionary where the keys are subject age groups, and the values are lists
containing the height of different people of each age group. You want to create a new dictionary
using dictionary comprehension where the keys are age_groups, and the values are average
height in each age group. Given the dictionary of heights:
Input: heights= { 'Child' : [30, 40, 35, 45, 30] , 'Teenage' : [50, 60, 55, 65, 60] , 'Adult' : [85,
90, 92, 88, 82] }
Sample Output: {'Child' : 36.0, 'Teenage' : 58.0, 'Adult' : 87.4}
8. Imagine you have a list of temperatures in Celsius and you want to convert them to
Fahrenheit. You have the conversion formula: Fahrenheit = (Celsius * 9/5) + 32. Given a list of
temperatures in Celsius: celsius_temps = [0, 10, 20, 30, 40, 50], write a Python program using
the map function to convert these temperatures to Fahrenheit. Print the result as a list.

You might also like