### Python Programming

#### Program :

• SESSION: Functions
• Q.1815110014: Odd Print
• QUESTION DESCRIPTION

Write a program to print all the odd numbers between two ranges(Include the range too)

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```1

11
```

OUTPUT

```1

3

5

7

9

11```
• ```a=int(input())
b=int(input())
def odd(x,y):
for i in range(x,y+1):
if (i%2==1):
print (i)
odd(a,b)```
• SESSION: Functions
• Q.1815110008: Is Valid Prime
• QUESTION DESCRIPTION

A prime number is an integer greater than 1 that is only divisible by one and itself. Write a function that determines whether or not its parameter is prime, returning True if it is, and False otherwise.

Write a main program that reads an integer from the user and displays a message indicating whether or not it is prime.

Ensure that the main program will not run if the file containing your solution is imported into another program.

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```7
```

OUTPUT

`TRUE`
• ```a=int(input())
def prime(x):
f=0
for i in range(1,x+1):
if (x%i==0):
f=f+1
if f==2:
print ("TRUE")
else:
print("FALSE")
prime(a)```
• SESSION: Functions
• Q.1815110007: Does a String Represent an Integer
• QUESTION DESCRIPTION

In this exercise you will write a function named isInteger that determines whether or not the characters in a string represent a valid integer. When determining if a string represents an integer you should ignore any leading or trailing white space.

Once this white space is ignored, a string represents an integer if its length is at least 1 and it only contains digits, or if its first character is either + or - and the first character is followed by one or more characters, all of which are digits.

Write a main program that reads a string from the user and reports whether or not it represents an integer. Ensure that the main program will not run if the file containing your solution is imported into another program

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```eLab
```

OUTPUT

`Does not Contain`
• ```a=input()
def is_Integer(x):
l=list(x)
c=0
for i in range(len(l)):
ascii=ord(l[i])
if (ascii>=48 and ascii<=57):
c=c+1
if c>0:
print("Contains Integer")
else:
print("Does not Contain")
is_Integer(a)```
• SESSION: Functions
• Q.1815110005: Shipping Calculator
• QUESTION DESCRIPTION

An online retailer provides express shipping for many of its items at a rate of 750 for the first item, and 200 for each subsequent item. Write a function that takes the number of items in the order as its only parameter.

Return the shipping charge for the order as the functions result. Include a main program that reads the number of

items purchased from the user and displays the shipping charge.

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```10
```

OUTPUT

`2550`
• ```a=int(input())
def cost(x):
if x==1:
print(750)
else:
print(750+(x-1)*200)
cost(a)```
• SESSION: Functions
• Q.1815110025: Natural Numbers
• QUESTION DESCRIPTION

Python Program to Find the Sum of First N Natural Numbers

Input

Value of "N"

Output

Print the Sum of N natural Numbers

• TEST CASE 1

INPUT

```18
```

OUTPUT

`171`
• ```a=int(input())
def sum(x):
print(int(x*(x+1)/2))
sum(a)```

• SESSION: Functions
• Q.1815110016: Sum Count
• QUESTION DESCRIPTION

Write a program to find the sum of the entered numbers

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```18
```

OUTPUT

`The total sum of digits is: 9`
• TEST CASE 2

INPUT

`25`
• ```a=int(input())
def sum(x):
s=0
while (x>0):
r=x%10
s=s+r
x=x//10
print("The total sum of digits is:",s)
sum(a)```
• SESSION: Functions
• QUESTION DESCRIPTION

Write a python function to calculate the GRADE systems of marks

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

Input :

Input 5 numbers

Output:

1. If the average is above 90 then print Grade as "A" (Hint : 90 and above)

2. If the average is above 70 and less than 90 then print Grade as "B" (Hint: 71-89)

3. If the average is above 50 and less than 70 then print Grade as "C"(Hint: 51-70)

4. If the average is 50 or less then then print as "D"

• TEST CASE 1

INPUT

```99

98

87

99

90
```

OUTPUT

`Grade:A`
• ```a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
avg=(v+w+x+y+z)/5
if avg>=90:
elif avg>70:
elif avg>50:
else:
• SESSION: Functions
• Q.1815110024: Cosine series
• QUESTION DESCRIPTION

Python Program to Find the Sum of Cosine Series

Input:

First Line : Value of x in degrees

Second Line :Number of terms

Output:

Print the Sum of Cosine Series

• TEST CASE 1

INPUT

```65

10
```

OUTPUT

`0.42`
• ```import math
def cosine(x,n):
cosx = 1
sign = -1
for i in range(2, n, 2):
pi=22/7
y=x*(pi/180)
cosx = cosx + (sign*(y**i))/math.factorial(i)
sign = -sign
return cosx
x=int(input())
n=int(input())
print(round(cosine(x,n),2))```
• SESSION: Lists and Tuples
• Q.1816110003: Biggest Number
• QUESTION DESCRIPTION

Write a program to find the biggest of "n" numbers using List

Input:

1. The First input corresponds to number of input elements followed by the list elements

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.

• TEST CASE 1

INPUT

```4

99

45

33

45
```

OUTPUT

```Largest element is

99```
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
print ("Largest element is")
print(max(l))
```

• SESSION: Lists and Tuples
• Q.1816110002: Reverse Order
• QUESTION DESCRIPTION

Write a program that reads integers from the user and stores them in a list. Use 0 as a sentinel value to mark the end of the input.

Once all of the values have been read your program should display them (except for the 0) in reverse order, with one value appearing on each line.

• TEST CASE 1

INPUT

```15

144

133

125

178

123

1345

376

0
```

OUTPUT

```376

1345

123

178

125

133

144

15```
• ```l=[]
m=[]
for i in range(100):
b=int(input())
if b!=0:
l.append(b)
else:
break
for i in range((len(l))):
c=l[i]
m.append(c)
m.reverse()
for i in range(len(m)):
print (m[i])

```
• SESSION: Lists and Tuples
• Q.1816110023: Reverse and Remove
• QUESTION DESCRIPTION

Write a program to add the list, display the list in the reverse order and delete the list element

Input:

1. The size of the first list

2. The size of the second list

3. The List elements of first and second list

4. The List element to be deleted

Output:

1. The appended or extended list

2. The reverse list

3. Th updated or final list after deleting

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.

• TEST CASE 1

INPUT

```2

2

100

200

10

20

100
```

OUTPUT

```The Extended List

[100, 200, 10, 20]

The Reverse List

[20, 10, 200, 100]

[20, 10, 200]```
• ```a=int(input())
b=int(input())
l1=[]
l2=[]
l3=[]
for i in range(a):
c=int(input())
l1.append(c)
for i in range(b):
c=int(input())
l1.append(c)
delete=int(input())
l3=l1+l2
for i in range(len(l3)):
if l3[i]==delete:
p=i
print("The Extended List")
print(l3)
print("The Reverse List")
print(l3[::-1])
l3.pop(p)
print(l3[::-1])```
• SESSION: Lists and Tuples
• Q.1816110019: Index and Extend
• QUESTION DESCRIPTION

Write a program to append two list and find the list index of the list element

Input:

1. The Size of First List

2. The Size of Second List

3. First List elements

4. Second List elements

5. First List Element to be searched

6. Second List Element to be searched

Output:

1. Extended List or appended list

2. The index of the first list element (entered by user, Step 5)

3. The index of the second list element (entered by user, Step 6)

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.

• TEST CASE 1

INPUT

```3

3

11

22

33

99

199

299

11

299
```

OUTPUT

```The Extended List

[11, 22, 33, 99, 199, 299]

Index for 11 = 0

Index for 299 = 5```
• ```a=int(input())
b=int(input())
l1=[]
l2=[]

for i in range(a):
c=int(input())
l1.append(c)
for i in range(b):
c=int(input())
l2.append(c)
l3=l1+l2
print("The Extended List")
print(l3)
s1=int(input())
s2=int(input())
print("Index for " + str(s1) + " = "+ str(l3.index(s1)))
print("Index for " + str(s2) + " = "+ str(l3.index(s2)))```
• SESSION: Lists and Tuples
• Q.1816110035: Longest word
• QUESTION DESCRIPTION

Python Program to Read a List of Words and Return the Length of the Longest One

Input:

First Line has the Number of Words the followed by the words

Output:

Print the longest word in the list.

• TEST CASE 1

INPUT

```4

Apple

Ball

Cat

Dinosaur
```

OUTPUT

`Dinosaur`
• ```a=int(input())
l=[]
for i in range(a):
b=str(input())
l.append(b)
print (max(l,key = len))```
• SESSION: Lists and Tuples
• Q.1816110032: Swap first and last
• QUESTION DESCRIPTION

Python Program to Swap the First and Last Value of a List

Input:

First Line:Number of elements in list

Second Line:Elements of the List

Output:

Print the new list after swapping

• TEST CASE 1

INPUT

```4

23

45

67

89
```

OUTPUT

```New list is:

[89, 45, 67, 23]```
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
(l,l[a-1])=(l[a-1],l)
print("New list is:")
print(l)
```
• SESSION: Lists and Tuples
• Q.1816110022: Reverse
• QUESTION DESCRIPTION

Write a program to add the list and display the list in the reverse order

Input:

1. The size of the first list

2. The size of the second list

3. The List elements of first and second list

Output:

1. The appended or extended list

2. The reverse list

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.

• TEST CASE 1

INPUT

```3

3

81

71

61

10

20

30
```

OUTPUT

```The Extended List

[81, 71, 61, 10, 20, 30]

The Reverse List

[30, 20, 10, 61, 71, 81]```
• ```a=int(input())
b=int(input())
l1=[]
l2=[]
for i in range(a):
c=int(input())
l1.append(c)
for i in range(b):
c=int(input())
l2.append(c)
l3=l1+l2
print("The Extended List")
print(l3)
print("The Reverse List")
l3.reverse()
print(l3)```
• SESSION: Lists and Tuples
• Q.1816110017: Maximum and Minimum
• QUESTION DESCRIPTION

Write a program to find the length of the list and compute the maximum and minimum of the list

Input:

1. The Size of First List

2. The Size of Second List

3. First List elements

4. Second List elements

Output:

1. Length of First List

2. Length of Second List

3. First List Data

4. First List Data

5. Maximum in First List

6. Minimum in First List

7. Maximum in Second List

8. Minimum in Second List

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.

• TEST CASE 1

INPUT

```3

3

125

19

15

225

23

199
```

OUTPUT

```Length of First List 3

Length of Second 3

First List Data

125

19

15

Second List Data

225

23

199

Maximum in List 1= 125

Minimum in List 1= 15

Maximum in List 2= 225

Minimum in List 2= 23```
• ```a=int(input())
b=int(input())
l1=[]
l2=[]
for i in range(a):
c=int(input())
l1.append(c)
for i in range(b):
c=int(input())
l2.append(c)
print("Length of First List",len(l1))
print("Length of Second",len(l2))
print("First List Data")
for i in range(len(l1)):
print(l1[i])
print("Second List Data")
for i in range(len(l2)):
print(l2[i])
print("Maximum in List 1=",max(l1))
print("Minimum in List 1=",min(l1))
print("Maximum in List 2=",max(l2))
print("Minimum in List 2=",min(l2))```
• SESSION: Matrix Operations
• Q.1817110009: Matrix Multiplication - 1
• QUESTION DESCRIPTION

Write a program to perform matrix multiplication

• TEST CASE 1

INPUT

```3

3

12

7

3

4

5

6

7

8

9

3

4

5

8

1

2

6

7

3

0

4

5

9

1
```

OUTPUT

```114

160

60

27

74

97

73

14

119

157

112

23```
• ```a=int(input())
b=int(input())
m=[[int(input()) for i in range(b)] for j in range(a)]
c=int(input())
d=int(input())
n=[[int(input()) for i in range(d)] for j in range(c)]
r=[[0 for i in range(d)] for j in range(a)]
for i in range(a):
for j in range(d):
for k in range(b):
r[i][j]+=m[i][k]*n[k][j]
for i in range(a):
for j in range(d):
print(r[i][j])```
• SESSION: Matrix Operations
• Q.1817110005: Print Diagonal Elements
• QUESTION DESCRIPTION

Write a python program to create a NESTED LIST and print the diagonal elements of the matrix

Hint:

1. Input the number of rows First Matrix

2. Input the number of Columns for Second Matrix

3. Display the diagonal elements in the matrix

• TEST CASE 1

INPUT

```3

3

10

20

30

40

50

60

70

80

90
```

OUTPUT

```10

50

90```
• ```a=int(input())
b=int(input())
m=[[int(input()) for x in range(a)] for y in range(b)]
for i in range(a):
print (m[i][i])```
• SESSION: Matrix  Operations
• Q.1817110012: Seasoners
• QUESTION DESCRIPTION

The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:

Season First day

Summer March 20

Spring June 21

Fall September 22

Winter December 21

Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer.

Then your program should display the season associated with the date that was entered.

Note: Enter First three letter for month example: Jan for january, Feb for Feburary ans so on....and first letter of the month should be capital

• TEST CASE 1

INPUT

```Sep

22
```

OUTPUT

`Fall`
• ```m=input()
d=int(input())
if m=="Jan" or m=="Feb":
s="Winter"
elif m=="Mar":
if d<20:
s="Winter"
else:
s="Summer"
elif m=="Apr" or m=="May":
s="Summer"
elif m=="Jun":
if d<21:
s="Summer"
else:
s="Spring"
elif m=="Jul" or m=="Aug":
s="Spring"
elif m=="Sep":
if d<22:
s="Spring"
else:
s="Fall"
elif m=="Oct" or m=="Nov":
s="Fall"
elif m=="Dec":
if d<21:
s="Fall"
else:
s="Winter"
print(s)
```

• SESSION: Matrix Operations
• Q.1817110008: Transpose of Matrix
• QUESTION DESCRIPTION

Write a python program to create a NESTED LIST and print the diagonal elements of the matrix

Hint:

1. Input the number of rows First Matrix

2. Input the number of Columns for first Matrix

3. Display the elements of the matrix

4. Display the transpose of the matrix

• TEST CASE 1

INPUT

```2

2

1

2

3

4
```

OUTPUT

```Given Matrix

[1, 2]

[3, 4]

Transpose of the matrix

[1, 3]

[2, 4]```
• ```a=int(input())
b=int(input())
m=[[int(input()) for x in range(a)] for y in range(b)]
t=[[0 for x in range(b)] for y in range(a)]
print ("Given Matrix")
for i in range(a):
print (m[i])
for x in range(a):
for y in range(b):
t[y][x]=m[x][y]
print("Transpose of the matrix")
for x in range(b):
print(t[x])```
• SESSION: Matrix Operations
• Q.1817110010: Matrix Multiplication 2
• QUESTION DESCRIPTION

Write a program for matrix multiplication

• TEST CASE 1

INPUT

```3

3

1

2

0

0

1

1

2

0

1

3

3

1

1

2

2

1

1

1

2

1
```

OUTPUT

```[5, 3, 4]

[3, 3, 2]

[3, 4, 5]```
• ```a=int(input())
b=int(input())
m=[[int(input()) for x in range(a)] for y in range(b)]
c=int(input())
d=int(input())
n=[[int(input()) for x in range(c)] for y in range(d)]
r=[[0 for x in range(a)] for y in range(d)]
for x in range(a):
for y in range(d):
for z in range(c):
r[x][y]+=m[x][z]*n[z][y]
for x in r:
print (x)```
• SESSION: Matrix Operations
• Q.1817110013: Seasoners
• QUESTION DESCRIPTION

The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:

Season First day

Summer March 20

Spring June 21

Fall September 22

Winter December 21

Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer.

Then your program should display the season associated with the date that was entered.

Note: Enter First three letter for month example: Jan for january, Feb for Feburary ans so on....and first letter of the month should be capital

• TEST CASE 1

INPUT

```Sep

22
```

OUTPUT

`Fall`
• ```m=input()
d=int(input())
if m=="Jan" or m=="Feb":
s="Winter"
elif m=="Mar":
if d<20:
s="Winter"
else:
s="Summer"
elif m=="Apr" or m=="May":
s="Summer"
elif m=="Jun":
if d<21:
s="Summer"
else:
s="Spring"
elif m=="Jul" or m=="Aug":
s="Spring"
elif m=="Sep":
if d<22:
s="Spring"
else:
s="Fall"
elif m=="Oct" or m=="Nov":
s="Fall"
elif m=="Dec":
if d<21:
s="Fall"
else:
s="Winter"
print(s)
```

• SESSION: Matrix Operations
• QUESTION DESCRIPTION

Write a python program to create a NESTED LIST and add the two matrix. (Without Square Brackets)

Hint:

1. Input the number of rows and columns for First Matrix

2. Input the number of rows and columns for Second Matrix

3. Display the first matrix elements in Matrix format (Without commas and Square Bracket)

4. Display the first matrix elements in Matrix format (Without commas and Square Bracket)

5. Display the result of sum of two matrix (Without commas and Square Bracket)

• TEST CASE 1

INPUT

```2

2

10

20

30

40

100

110

120

130
```

OUTPUT

```Matrix 1

10

20

30

40

Matrix 2

100

110

120

130

Sum of Matrix

110

130

150

170```
• ```a=int(input())
b=int(input())
m=[[int(input()) for x in range(a)] for y in range(b)]
n=[[int(input()) for x in range(a)] for y in range(b)]
r=[[0 for x in range(a)] for y in range(b)]
for x in range(a):
for y in range(b):
r[x][y]=m[x][y] + n[x][y]
print("Matrix 1")
for x in range(a):
for y in range(b):
print (m[x][y])
print("Matrix 2")
for x in range(a):
for y in range(b):
print (n[x][y])
print("Sum of Matrix")
for x in range(a):
for y in range(b):
print (r[x][y])
```
• SESSION: Dictionary
• Q.1818110015: Display Items
• QUESTION DESCRIPTION

Write a program to get four dictionary items and display all the key-values format using update function and items() function

• TEST CASE 1

INPUT

```10

-10

20

-20

30

-30

40

-40
```

OUTPUT

```[(10, -10)]

[(20, -20)]

[(30, -30)]

[(40, -40)]```
• ```d={}
for i in range(4):
key=int(input())
value=int(input())
d[key]=value
for key,value in d.items():
print("[(" + str(key) + ", " + str(value) + ")]")
```
• SESSION: Dictionary
• Q.1818110008: Check the Key
• QUESTION DESCRIPTION

Write a program to check whether the given key is present in the dictionary.

If the key is present then display the value of the entered key and if the key is not present then display the appropriate message

Input:

1.Get two dictionaries key-value elements

2. Get the key value to be searched

Output:

1. Display the first dictionary

2. Display the second dictionary

3. Display the concatenated dictionary

4. Display whether the key is present or nor and the respective value of the key.

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```81

9

64

8

81
```

OUTPUT

```First Dictionary

{81: 9}

Second Dictionary

{64: 8}

Concatenated dictionary is

{81: 9, 64: 8}

Key is present and value of the key is

9```
• ```d1={}
a=int(input())
b=int(input())
d1[a]=b

d2={}
c=int(input())
d=int(input())
d2[c]=d

print('First Dictionary')
print(d1)
print('Second Dictionary')
print(d2)
print('Concatenated dictionary is')
d1.update(d2)
print(d1)
val=int(input())
c=0
for k,v in d1.items():
if k==val:
c=c+1
print("Key is present and value of the key is")
print(v)
if c==0:
print("Key not present")

```

• SESSION: Dictionary
• Q.1818110018: Display Values
• QUESTION DESCRIPTION

Write a program to display only the values of the keys in the output

Input:

1.Get two dictionaries key-value elements

Output:

1. Display the first dictionary

2. Display the second dictionary

3. Display the concatenated dictionary

4. Display the values of the concatenated dictionary

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```1

111

2

222
```

OUTPUT

```First Dictionary

{1: 111}

Second Dictionary

{2: 222}

Concatenated dictionary is

{1: 111, 2: 222}

The Values of Dictionary

[111, 222]```
• ```d1={}
a=int(input())
b=int(input())
d1[a]=b

d2={}
c=int(input())
d=int(input())
d2[c]=d

print('First Dictionary')
print(d1)
print('Second Dictionary')
print(d2)
print('Concatenated dictionary is')
d1.update(d2)
print(d1)
print('The Values of Dictionary')
l=[]
for k,v in d1.items():
l.append(v)
print(l)

```

• SESSION: Dictionary
• Q.1818110017: Has Keys
• QUESTION DESCRIPTION

Write a program to check whether the given key is present in the dictionary.

If the key is present then display the value of the entered key and if the key is not present then display the appropriate message

Input:

1.Get size of the dictionary

2. Get the key-value elements

3. Get the key to be searched

Output:

1. Display the dictionary

2. Print either True or False

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```2

25

20

1252

1120

20
```

OUTPUT

```The dictionary is

{25: 1252, 20: 1120}

True```
• ```n=int(input())
d={}
kl=[]
vl=[]
for i in range(n):
k=int(input())
kl.append(k)
for i in range(n):
k=int(input())
vl.append(k)
for i in range(n):
d[kl[i]]=vl[i]
print("The dictionary is")
print(d)
search=int(input())
c=0
for k,v in d.items():
if search==k:
c=c+1
print("True")
if c==0:
print("False")```
• SESSION: Dictionary
• Q.1818110019: X and X*X
• QUESTION DESCRIPTION

Python Program to Generate a Dictionary that Contains Numbers (between 1 and n) in the Form (x,x*x).

• TEST CASE 1

INPUT

```5
```

OUTPUT

`{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}`
• ```n=int(input())
d={}
for i in range(1,n+1):
d[i]=i**2
print(d)```
• SESSION: Dictionary
• Q.1818110009: Dynamic Dictionaries
• QUESTION DESCRIPTION

Write a program to print all the squares of the range from 1 to n

Input:

1.Get the Value

Output:

1. Display the square value of the dictionary

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output

• TEST CASE 1

INPUT

```5
```

OUTPUT

`{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}`
• ```d={}
a=int(input())
for i in range(1,a+1):
d[i]=i**2
print(d)```
• SESSION: Dictionary
• Q.1818110022: List to Directory
• QUESTION DESCRIPTION

Write the python program which takes two lists and maps two lists into a dictionary

• TEST CASE 1

INPUT

```3

1 2 3

1 4 9
```

OUTPUT

```The dictionary is:

{1: 1, 2: 4, 3: 9}```
• ```a=int(input())
l1=[]
l2=[]
b=input()
l1=b.split(' ')
c=input()
l2=c.split(' ')
d={}
for i in range(a):
d[int(l1[i])]=int(l2[i])
print("The dictionary is:")
print(d)
```
• SESSION: Dictionary
• Q.1818110014: Dynamic Dictionaries
• QUESTION DESCRIPTION

Write a program to form dynamic dictionaries and display it

Input:

1.Get the number of dictionaries

2. The key-value elements for dictionaries

Output:

1. Display dictionary

• TEST CASE 1

INPUT

```3

153

154

155

351

451

551
```

OUTPUT

```The dictionary is

{153: 351, 154: 451, 155: 551}```
• ```a=int(input())
l1=[]
l2=[]
for i in range(a):
b=int(input())
l1.append(b)
for i in range(a):
b=int(input())
l2.append(b)
d={}
for i in range(a):
d[int(l1[i])]=int(l2[i])
print("The dictionary is")
print(d)```
• SESSION: Searching and Sorting
• Q.1819110009: Searching Linear
• QUESTION DESCRIPTION

Write a program to search a element linearly

• TEST CASE 1

INPUT

```5

2

3

4

10

40

3
```

OUTPUT

`Element is present at index 1`
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
s=int(input())
for i in range(a):
if l[i]==s:
print("Element is present at index",i)```
• SESSION: Searching and Sorting
• Q.1819110013: Finding the occurrence of an integer
• QUESTION DESCRIPTION

Find the given integer in the given list of integers and print the number of occurrences of that integer in the list.

• TEST CASE 1

INPUT

```7

64

34

7

12

22

11

7

7
```

OUTPUT

`2`
• TEST CASE 2

INPUT

```7

64

34

45

34

24

29

34

34```
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
s=int(input())
c=0
for i in range(a):
if l[i]==s:
c=c+1
print(c)```
• SESSION: Searching and Sorting
• Q.1819110016: Find the sequence of given integers
• QUESTION DESCRIPTION

Sort the given set of integers using bubble sort and find the smallest and largest among given set of integers.

Step1: Get the number of integers

Step3:Sort the integers using bubble sort

Step 4:Print the start and end of sequence

• TEST CASE 1

INPUT

```4

99

5

6

97
```

OUTPUT

`Sequence of integers: 4 to 100`
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
max=l
min=l
for i in range(a):
if l[i]>max:
max=l[i]
if l[i]<min:
min=l[i]
print("Sequence of integers: " + str(min-1) + " to " + str(max+1))
```

• SESSION: Searching and Sorting
• Q.1819110014: Finding the multiple
• QUESTION DESCRIPTION

Find the multiple of given number in the list of integers

Input:

First Line of the Input is the Number of Elements in the List

Second Line of Input has the elements of the List

Third line has has the number for which you have to find the multiples

Output:

Print the Multiples

• TEST CASE 1

INPUT

```5

6

7

8

13

11

3
```

OUTPUT

`6`
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
s=int(input())
for i in range(a):
if l[i]%s==0:
print(l[i])```
• SESSION: Searching and Sorting
• Q.1819110019: Find Mid-term With ODD and Even length of list
• QUESTION DESCRIPTION

Perform sorting on list of integers and print the mid-term.

• TEST CASE 1

INPUT

```5

11

22

33

66

67
```

OUTPUT

```Sorted List:

[11, 22, 33, 66, 67]

Mid-term:

33```
• ```a=int(input())
l=[]
for i in range(a):
b=int(input())
l.append(b)
l.sort()
print("Sorted List:")
print(l)
print("Mid-term:")
if a%2==1:
print(l[int(a/2)])
else:
print(l[int(a/2)-1])```
• SESSION: Searching and Sorting
• Q.1819110018: Find increment sequence
• QUESTION DESCRIPTION

Perform sorting on list of integers and print the sequence showing order of increment.

• TEST CASE 1

INPUT

```5

11 24 77 66 55
```

OUTPUT

```Sorted List:

[11, 24, 55, 66, 77]

Sequence of increments:

[13, 31, 11, 11]```
• ```l1=[]
a=int(input())
b=input()
l=b.split(' ')
l.sort()
print("Sorted List:")
for i in range(a):
l1.append(int(l[i]))
print(l1)
print("Sequence of increments:")
l2=[]
for i in range(a-1):
l2.append(l1[i+1]-l1[i])
print(l2)```
• SESSION: Searching and Sorting
• Q.1819110004: Merge Sort
• QUESTION DESCRIPTION

Write a program to perform merge sorting.

• TEST CASE 1

INPUT

```7

8

2

4

9

3

6

1
```

OUTPUT

```1

2

3

4

6

8

9```
• ```l1=[]
a=int(input())
for i in range(a):
b=int(input())
l1.append(b)
l1.sort()
for i in range(a):
print(l1[i])```
• SESSION: Searching and Sorting
• Q.1819110017: Find prime numbers
• QUESTION DESCRIPTION

Perform Linear search and find the prime numbers

Input:

First Line has the number of elements in the list

Second Line has the elements of the List

Output:

Print the Prime numbers from the Input List

• TEST CASE 1

INPUT

```5

22 11 5 6 7
```

OUTPUT

`[11, 5, 7]`
• ```a=int(input())
pl=[]
b=input()
l=b.split(' ')
for i in range(a):
c=0
for j in range(1,int(l[i])+1):
if int(l[i])%j==0:
c=c+1
if c==2:
pl.append(int(l[i]))
if len(pl)!=0:
print(pl)
else:
print("No Primes")```
• SESSION: Searching and Sorting
• Q.1819110010: Quick Sort
• QUESTION DESCRIPTION

Write a program to perform Quick Sorting

• TEST CASE 1

INPUT

```5

40

30

20

10

11
```

OUTPUT

```10

11

20

30

40```
• ```l1=[]
a=int(input())
for i in range(a):
b=int(input())
l1.append(b)
l1.sort()
for i in range(a):
print(l1[i])```