Professional Documents
Culture Documents
Name-Utkarsh Singh
Roll No.-1900520130058
Branch-IT(4th Sem.)
1. Given a list, iterate it, and display numbers divisible by five, and if you find a
number greater than 150, stop the loop iteration.
Code:
l=list(map(int,input().strip().split()))
for i in l:
if i==150:
break;
if i%5==0:
print(i)
Code:
def outer_function(a,b):
c=0
def inner_function(a,b):
return a+b
c=inner_function(a,b)
return c+5
a=int(input())
b=int(input())
print(outer_function(a, b))
3. Given a list slice it into 3 equal chunks and reverse each chunk.
Code:
def divide_chnks(l,n):
for i in range(0,n,3):
yield l[i:i+3][::-1]
l=list(map(int,input().strip().split()))
x=list(divide_chnks(l, n))
print(x)
4. Given two strings, s1 and s2, create a new string by appending s2 in the middle of
s1.
Code:
n=len(s1)//2
s3=s1[:n]+s2+s1[n:]
print(s3)
Code:
def dectoOct(decimal):
if(decimal > 0):
dectoOct((int)(decimal/8))
print(decimal%8, end='')
print(decimal)
dectoOct(decimal)
Code:
return(dict1.update(dict2))
Merge(dict1, dict2)
print(dict1)
Code:
print(tuple1)
print(tuple1.count(50))
Code:
import random
otp = random.randint(100000, 999999)
print("OTP:", otp)
Code:
import math,random
def generateOTP() :
digits = "0123456789"
specialsymbol="@#$%&!"
uppercase_letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
all1=digits+specialsymbol+uppercase_letters
password=""
for i in range(6) :
for i in range(2) :
for i in range(1) :
for i in range(1) :
return password
x=generateOTP()
print(x)
10. Return array of odd rows and even columns from given numpy array.
Code:
Import numpy
arr=numpy.array([[3, 6, 9, 12], [15, 18, 21, 24], [27, 30, 33, 36], [39, 42, 48], [51, 54, 57, 60]])
print(“Printing input array”)
print(arr)
print(“Printing array of odd rows & even columns”)
newArr=arr[::2, 1::2]
print(newArr)