You are on page 1of 4

*********************************************************************************************************

Name : Aayaan Mukherjee


Roll no. : 13414
Dept : Computer Science
Year : First
Subject : Python
*********************************************************************************************************

Question : 1
def func():
x=int(input("Enter the length of the list: "))
L=[]
for i in range(x):
x2=int(input("Enter : "))
L.append(x2)
return L
print(func())

Output :
Enter the length of the list: 5
Enter : 1
Enter : 2
Enter : 3
Enter : 4
Enter : 5
[1, 2, 3, 4, 5]

***************

Question : 2
def func():
x=int(input("Enter the length of the list: "))
L=[];s=0
for i in range(x):
x2=int(input("Enter : "))
s+=x2
L.append(s)
return L
print(func())
Output :
Enter the length of the list: 4
Enter : 1
Enter : 2
Enter : 3
Enter : 4
[1, 3, 6, 10]

***************

Question : 3

def func(y):
L=''; d={}
for i in y:
if i not in L:
L+=i
d[i]=y.count(i)
else:
pass
return d
x=input("Enter a sentence: ")
print(func(x))

Output :

Enter a sentence: i m with you

{'i': 2, ' ': 3, 'm': 1, 'w': 1, 't': 1, 'h': 1, 'y': 1, 'o': 1, 'u':
1}

***************
Question : 4
def func():
x=int(input("Enter the length of the list: "))
L=[];s=0;s2=[]
for i in range(1,x+1):
for j in range(1,6):
s=j*i
s2.append(s)
L.append(s2)
s2=[]
return L
print(func())

Output :
Enter the length of the list: 4
[[1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12,
16, 20]]

***************

Question : 5

d={1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',
8:'eight',9:'nine',0:"zero"}
def func(num):
s=''
for i in num:
s+=d[int(i)]+' '
return s

num1=input("Enter number: ")


print(func(num1))

Output :
Enter number: 567
five six seven
***************

You might also like