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

Ayush (0301CS211029) Assignment 3

The document contains 6 programming assignments involving list operations in Python. The assignments include: 1) Creating a list of numbers and printing averages, 2) Replacing '+' in list items with spaces, 3) Filling odd and even lists from 1-100, 4) Creating a random list from words and counting occurrences, 5) Multiplying numbers in two lists based on digit length, 6) Extracting names from email IDs. For each assignment, Python code is provided to solve the problem.

Uploaded by

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

Ayush (0301CS211029) Assignment 3

The document contains 6 programming assignments involving list operations in Python. The assignments include: 1) Creating a list of numbers and printing averages, 2) Replacing '+' in list items with spaces, 3) Filling odd and even lists from 1-100, 4) Creating a random list from words and counting occurrences, 5) Multiplying numbers in two lists based on digit length, 6) Extracting names from email IDs. For each assignment, Python code is provided to solve the problem.

Uploaded by

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

#Name- Ayush

#Enrollment Num - 0301CS211034

#3 : List Assignment

#1) Create a list with the following values:


56.7,78,45.3,89,19.9,32.9,10.0,22.1,45.9,55.6

#Output the result as follows:


#The average of Player 1 is : 56.7
#The average of Player 2 is : 78
#.......
#.......
#The average of Player 10 is : 55.6

list = [56.7,78,45.3,89,19.9,32.9,10.0,22.1,45.9,55.6]
for L in range(len(list)):
print("The average of player is : {0}".format(list[L]))

#2) Create a list with these values:


#'computer+program', 'new+delhi', 'artificial+intelligence', 'sea+facing',
'bungalow+society',
#'software+engineer', 'highspeed+internet', 'slow+coach', 'high+density',
'clear+weather'
#Output to be in the format
#Computer Program
#New Delhi
#......

list = ['computer+program', 'new+delhi', 'artificial+intelligence', 'sea+facing',


'bungalow+society','software+engineer', 'highspeed+internet', 'slow+coach',
'high+density', 'clear+weather']
for L in list:
list2 = L.replace('+', ' ')
print(list2)

#3) Create two empty lists 'odd_list', 'even_list'


#Using a loop, fill the
#'odd_list' with odd values between 1-100 and
#'even_list' with even values between 1-100

odd_list=[]
even_list=[]
L=1
for L in range(100):
if(L%2==0):
even_list.append(L)
else:
odd_list.append(L)
print(odd_list)
print(even_list)

#4) Create a list with random occurances of the values


#"data", science", "machine", "learning" (Do not hardcode)
#Find the count of each word

import random
list= ["data", "science", "machine", "learning"]
list2=[]
cd=0
cs=0
cm=0
cl=0
for i in range(20):
list2.append(random.choice(list))
print(list2)

for i in range(len(list2)):
if(list2[i]=="data"):
cd +=1
elif(list2[i]=="science"):
cs+=1
elif(list2[i]=="machine"):
cm+=1
elif(list2[i]=="learning"):
cl+=1
print("Count of data : {0}".format(cd))
print("Count of science :{0} ".format(cs))
print("Count of machine : {0}".format(cm))
print("Count of machine :{0} ".format(cl))

#5) create 2 numeric lists having 1,2 and 3 digit numbers. (selected at random)
#The lists need not have the same count of numbers.
#Your task is to multiply
#all 1-digit number of list1 with all 1-digit numbers of list2
#all 2-digit numbers of list1 with all 2-digit numbers of list2
#all 3-digit numbers of list1 with all 3-digit numbers of list2

#eg: list1 = [1,5,102,45,100,75]


#list2 = [15,239,6]

#expected output
#---------------
#1*6 = 6
#5*6 = 30
#102*239 = 24378
#100*239 = 23900
#45*15 = 675
#75*15 = 1125

import random
n1=random.randint(1,9)
n2=random.randint(1,9)
n3=random.randint(1,9)
n4=random.randint(1,9)
n5=random.randint(1,9)
n6=random.randint(1,9)

list1=[]
list2=[]
for i in range(n1):
list1.append(random.randint(1,9))
for i in range(n2):
list1.append(random.randint(10,99))
for i in range(n3):
list1.append(random.randint(100,999))
for i in range(n3):
list2.append(random.randint(1,9))
for i in range(n4):
list2.append(random.randint(10,99))
for i in range(n5):
list2.append(random.randint(100,999))

for n1 in list1:
for n2 in list2:
if((n1>=1 and n1<=9) and (n2>=1 and n2<=9)):
print("{0} * {1} = {2}".format(n1,n2,n1*n2))

for n1 in list1:
for n2 in list2:
if((n1>=10 and n1<=99) and (n2>=10 and n2<=99)):
print("{0} * {1} = {2}".format(n1,n2,n1*n2))

for n1 in list1:
for n2 in list2:
if((n1>=100 and n1<=999) and (n2>=100 and n2<=999)):
print("{0} * {1} = {2}".format(n1,n2,n1*n2))

#6) A list contains the email IDs of employees of different organisations in the
following format:
#<firstname>.<lastname>@<domain>

#[email protected]
#[email protected]
#[email protected]
#[email protected]
#[email protected]
#[email protected]
#[email protected]

#Print all the employee names

list =
["[email protected]","[email protected]","sarita.patil@mycompany
.in","[email protected]","[email protected]","[email protected]",
"[email protected]"]

print("Employee names: ")


for i in list:
name = i.split('@')[0]
fname = name.split('.')[0]
lname = name.split('.')[1]
print("{0} {1}".format(fname,lname))

You might also like