0% found this document useful (0 votes)
9 views126 pages

Programming Using Python Lab Record - 240401012-1

The document outlines a programming curriculum for first-year B.Tech Biotechnology students at Rajalakshmi Engineering College, focusing on Python programming. It includes a comprehensive list of experiments covering algorithms, data types, control structures, and various operations on data structures like strings, lists, tuples, sets, and dictionaries. Additionally, it features specific coding exercises and their expected outputs to reinforce learning.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views126 pages

Programming Using Python Lab Record - 240401012-1

The document outlines a programming curriculum for first-year B.Tech Biotechnology students at Rajalakshmi Engineering College, focusing on Python programming. It includes a comprehensive list of experiments covering algorithms, data types, control structures, and various operations on data structures like strings, lists, tuples, sets, and dictionaries. Additionally, it features specific coding exercises and their expected outputs to reinforce learning.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

RAJALAKSHMI ENGINEERING COLLEGE

RAJALAKSHMI NAGAR, THANDALAM 602105

PROGRAMMING USING PYTHON

Akshaya Sri . S

Year I - [Link] Biotechnology - FA

2116240401006

II

2024-2025

1
List of Experiments

1. Study of algorithms, flowcharts and pseudocodes.


2. Introduction to Python Programming and Python
IDLE/Anaconda distribution.
3. Experiments based on Variables, Data Types and
Operators in Python.
4. Coding Standards and Formatting Output.
5. Algorithmic Approach: Selection control structures.
6. Algorithmic Approach: Iteration control structures.
7. Experiments based on Strings and its operations.
8. Experiments based on Lists and its operations.
9. Experiments based on Tuples and its operations.
10. Experiments based on Sets and its operations.
11. Experiments based on Dictionary and its operations.
12. Functions: Built-in functions.
13. Functions: User-defined functions.
14. Functions: Recursive functions.
15. Searching techniques: Linear and Binary.
16. Sorting techniques: Bubble and Merge Sort.
17. Experiments based on files and its operations.

2
CO-PO-PSO Mapping

3
INDEX
2116240401012 Barathkumar. S

[Link]
I Biotechnology FA

Page Teacher’s
S. No. Date Title No. Signature

Experiments based on Variables, Datatypes in Python


1.1 05/03/25 Strings to Integers 9

1.2 05/03/25 Gross Salary 10

1.3 05/03/25 Square Root 11

1.4 05/03/25 Gain Percent 12

1.5 05/03/25 Deposits 14

1.6 05/03/25 Carpenter 15

Operators in Python
2.1 12/03/25 Rotaract Club 18

2.2 12/03/25 Balance 20

2.3 12/03/25 Birthday Party 21

2.4 12/03/25 Integer Between 23

2.5 12/03/25 Dolls 24

2.6 12/03/25 Problem using Operators 25

2.7 12/03/25 Last Digit 27

2.8 12/03/25 Troy Battle 28

2.9 12/03/25 Widgets and Gizmos 29

2.10 12/03/25 Tax 30

Selection Control Structures in Python


3.1 23/03/25 Second Last Digit 32

3.2 23/03/25 Leap Year 33

3.3 23/03/25 Triangle Classification 34

3.4 23/03/25 Chinese Zodiac 36

4
3.5 23/03/25 Vowel or Consonant 38

3.6 23/03/25 Electricity Bill 40

3.7 23/03/25 Eligibility of Admission 42

3.8 23/03/25 Pythagorean Triple 44


3.9 23/03/25 IN/OUT 46

3.10 23/03/25 Length of Month 48

Algorithmic Approach: Iteration Control Structures


4.1 03/04/25 Product of Single Digits 51

4.2 03/04/25 Fibonacci 52

4.3 03/04/25 Count Of Non-Repeated Digits 53

4.4 03/04/25 Perfect Square after Adding 54

4.5 03/04/25 Prime Number 55

4.6 03/04/25 Disarium Number 56

4.7 03/04/25 Count of Unique Digits 57

4.8 03/04/25 Factorial 58

4.9 03/04/25 Sum of the Series 59

4.10 03/04/25 Next Perfect Square 60

Functions: Built-In Functions, User-Defined Functions, Recursive Functions


5.1 07/04/25 Automorphic Number 62
5.2 07/04/25 Coin Change 63

5.3 07/04/25 Abundant Number 64

5.4 07/04/25 Difference Sum 66

5.5 07/04/25 Check Product of Digits 67

Experiments based on Strings and Its Operations


6.1 03/05/25 Return Second Word in Uppercase 70

6.2 03/05/25 Reverse String 71

6.3 03/05/25 Order of Entry 72

6.4 03/05/25 Remove Characters 73

6.5 03/05/25 Repeat Letters in a String 74

5
6.6 03/05/25 Palindrome 75

6.7 03/05/25 Count Letters, Digits and Symbols 76

6.8 03/05/25 Username Domain Extension 77

6.9 03/05/25 Balanced Strings 78

6.10 03/05/25 First N Common Characters 79

Experiments based on Lists and Its Operations


7.1 07/05/25 Insert an Element 81

7.2 07/05/25 Distinct Elements in an Array 83

7.3 07/05/25 Frequency of Element 85

7.4 07/05/25 Index of Smallest Element 86

7.5 07/05/25 Print Element Location 88

7.6 07/05/25 Zip List 90

7.7 07/05/25 Strictly Increasing or Decreasing 92

7.8 07/05/25 Merge Array Without Duplication 94

7.9 07/05/25 Factors of a Number 96

7.10 07/05/25 Existence of 2 Indices 98

Experiments based on Tuples, Sets and Its Operations


8.1 14/05/25 Elimination of Common Elements 101

8.2 14/05/25 American Keyboard 103

8.3 14/05/25 Binary String 105

8.4 14/05/25 Repeated Number 106

8.5 14/05/25 DNA Sequence 107

Experiments based on Dictionary and Its Operations


9.1 28/05/25 Sort by Summation of Values 109

9.2 28/05/25 Max Votes 111

9.3 28/05/25 Scrabble 113

9.4 28/05/25 Uncommon Word 114

9.5 28/05/25 Test, Assignment and Lab Marks 115

6
Searching Techniques: Linear and Binary
10.1 28/05/25 Bubble Sorting 118

10.2 28/05/25 Bubble Sort and Find First & Last Element 119

10.3 28/05/25 Binary Search 121

10.4 28/05/25 Merge Sorting 122

10.5 28/05/25 Frequency of Numbers 123

Sorting Techniques: Bubble and Merge Sort


11.1 28/05/25 Bubble Sorting 125

11.2 28/05/25 Merge Sorting 126

7
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Experiments based on Variables, Datatypes in Python. / Week1_Coding

Status Finished
Started Saturday, 1 March 2025, 8:02 AM
Completed Wednesday, 5 March 2025, 6:24 PM
Duration 4 days 10 hours
Marks 6.00/6.00
Grade 100.00 out of 100.00

8
Question 1
Correct

Mark 1.00 out of 1.00

Write a program to convert strings to an integer and float and display its type.

Sample Input:

10
10.9

Sample Output:

10,<class 'int'>

10.9,<class 'float'>

For example:

Input Result

10 10,<class 'int'>
10.9 10.9,<class 'float'>

Answer: (penalty regime: 0 %)


1 a=int(input())
2 print(a,type(a),sep=",")
3 b=float(input())
4 print("%.1f"%b,type(b),sep=",")
5

Input Expected Got

10 10,<class 'int'> 10,<class 'int'>


10.9 10.9,<class 'float'> 10.9,<class 'float'>

12 12,<class 'int'> 12,<class 'int'>


12.5 12.5,<class 'float'> 12.5,<class 'float'>

89 89,<class 'int'> 89,<class 'int'>


7.56 7.6,<class 'float'> 7.6,<class 'float'>

55000 55000,<class 'int'> 55000,<class 'int'>


56.2 56.2,<class 'float'> 56.2,<class 'float'>

2541 2541,<class 'int'> 2541,<class 'int'>


2541.679 2541.7,<class 'float'> 2541.7,<class 'float'>

Passed all tests!

Correct

9
Marks for this submission: 1.00/1.00.

Question 2
Correct

Mark 1.00 out of 1.00

Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of his basic salary, and his house rent allowance is 20%
of his basic salary. Write a program to calculate his gross salary.
Sample Input:

10000

Sample Output:

16000

For example:

Input Result

10000 16000

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=(40/100)*a
3 c=(20/100)*a
4 d=a+b+c
5 print(d)

Input Expected Got

10000 16000 16000.0

20000 32000 32000.0

28000 44800 44800.0

5000 8000 8000.0

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

10
Question 3
Correct

Mark 1.00 out of 1.00

Write a simple python program to find the square root of a given floating point number. The output should be displayed with 3 decimal
places.

Sample Input:
8.00

Sample Output:

2.828

For example:

Input Result

14.00 3.742

Answer: (penalty regime: 0 %)


1 a=float(input())
2 b=(a**0.5)
3 print('%.3f'%b)

Input Expected Got

8.00 2.828 2.828

14.00 3.742 3.742

4.00 2.000 2.000

487 22.068 22.068

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

11
Question 4
Correct

Mark 1.00 out of 1.00

Alfred buys an old scooter for Rs. X and spends Rs. Y on its repairs. If he sells the scooter for Rs. Z (Z>X+Y). Write a program to help
Alfred to find his gain percent. Get all the above-mentioned values through the keyboard and find the gain percent.

Input Format:
The first line contains the Rs X

The second line contains Rs Y

The third line contains Rs Z

Sample Input:
10000
250

15000

Sample Output:

46.34 is the gain percent.

For example:

Input Result

45500 30.43 is the gain percent.


500
60000

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 c=int(input())
4 x=a+b
5 y=c-x
6 z=(y/x)*100
7 d=float(z)
8 print("%.2f"%d,"is the gain percent.")

Input Expected Got

10000 46.34 is the gain percent. 46.34 is the gain percent.


250
15000

45500 30.43 is the gain percent. 30.43 is the gain percent.


500
60000

12
Input Expected Got

5000 40.00 is the gain percent. 40.00 is the gain percent.


0
7000

12500 2.86 is the gain percent. 2.86 is the gain percent.


5000
18000

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

13
Question 5
Correct

Mark 1.00 out of 1.00

In many jurisdictions, a small deposit is added to drink containers to encourage people to recycle them. In one particular jurisdiction, drink
containers holding one liter or less have a $0.10 deposit and drink containers holding more than one liter have a $0.25 deposit. Write a
program that reads the number of containers of each size(less and more) from the user. Your program should continue by computing and
displaying the refund that will be received for returning those containers. Format the output so that it includes a dollar sign and always
displays exactly two decimal places.
Sample Input
10
20

Sample Output

Your total refund will be $6.00.

For example:

Input Result

20 Your total refund will be $7.00.


20

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 c=a*0.10
4 d=b*0.25
5 e=c+d
6 print('Your total refund will be $''%.2f.'%e)

Input Expected Got

20 Your total refund will be $7.00. Your total refund will be $7.00.
20

11 Your total refund will be $6.60. Your total refund will be $6.60.
22

123 Your total refund will be $62.30. Your total refund will be $62.30.
200

76 Your total refund will be $17.10. Your total refund will be $17.10.
38

Passed all tests!

Correct

Marks for this submission: 1.00/1.00.


14
Question 6
Correct

Mark 1.00 out of 1.00

Justin is a carpenter who works on an hourly basis. He works in a company where he is paid Rs 50 for an hour on weekdays and Rs 80 for an
hour on weekends. He works 10 hrs more on weekdays than weekends. If the salary paid for him is given, write a program to find the
number of hours he has worked on weekdays and weekends.

Hint:

If the final result(hrs) are in -ve convert that to +ve using abs() function

The abs() function returns the absolute value of the given number.
number = -20
absolute_number = abs(number)
print(absolute_number)
# Output: 20

Sample Input:
450

Sample Output:

weekdays 10.38

weekend 0.38

For example:

Input Result

450 weekdays 10.38


weekend 0.38

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=abs((a-500)/130)
3 c=b+10
4 print("weekdays","%.2f"%c)
5 print("weekend","%.2f"%b)

Input Expected Got

450 weekdays 10.38 weekdays 10.38


weekend 0.38 weekend 0.38

500 weekdays 10.00 weekdays 10.00


weekend 0.00 weekend 0.00

15
Input Expected Got

10000 weekdays 83.08 weekdays 83.08


weekend 73.08 weekend 73.08

6789 weekdays 58.38 weekdays 58.38


weekend 48.38 weekend 48.38

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week1_MCQ

Jump to...

Operators ►

16
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Operators and Formatting Output. / Week2_Coding

Status Finished
Started Thursday, 6 March 2025, 11:29 AM
Completed Wednesday, 12 March 2025, 8:19 PM
Duration 6 days 8 hours
Marks 19.00/19.00
Grade 100.00 out of 100.00

17
Question 1
Correct

Mark 1.00 out of 1.00

Note:
Dont use if-else. Operators alone must be used .

A team from the Rotract club had planned to conduct a rally to create awareness among the Coimbatore people to donate blood. They
conducted the rally successfully. Many of the Coimbatore people realized it and came forward to donate their blood to nearby blood banks.
The eligibility criteria for donating blood are people should be above or equal to 18 and his/ her weight should be above 40. There was a
huge crowd and staff in the blood bank found it difficult to manage the crowd. So they decided to keep a system and ask the people to
enter their age and weight in the system. If a person is eligible he/she will be allowed inside.
Write a program and feed it to the system to find whether a person is eligible or not.

Input Format:

Input consists of two integers that correspond to the age and weight of a person respectively.
Output Format:

Display True(IF ELIGIBLE)

Display False (if not eligible)

Sample Input
19
45
Sample Output

True

For example:

Input Result

18 False
40

Answer: (penalty regime: 0 %)


1 age=int(input())
2 weight=int(input())
3 print(age>=18 and weight>40)

18
Input Expected Got

19 True True
45

18 False False
40

18 True True
42

16 False False
45

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

19
Question 2
Correct

Mark 1.00 out of 1.00

Pretend that you have just opened a new savings account that earns 4 percent interest per year. The interest that you earn is paid at the end
of the year, and is added to the balance of the savings account. Write a program that begins by reading the amount of money deposited
into the account from the user. Then your program should compute and display the amount in the savings account after 1, 2, and 3 years.
Display each amount so that it is rounded to 2 decimal places. Sample Input: 10000 Sample Output: Balance as of end of Year 1: $10400.00.
Balance as of end of Year 2: $10816.00. Balance as of end of Year 3: $11248.64.
For example:

Input Result

10000 Balance as of end of Year 1: $10400.00.


Balance as of end of Year 2: $10816.00.
Balance as of end of Year 3: $11248.64.

Answer: (penalty regime: 0 %)


1 a=float(input())
2 b=a*1.04
3 c=b*1.04
4 d=c*1.04
5 print("Balance as of end of Year 1: $%.2f."%b)
6 print("Balance as of end of Year 2: $%.2f."%c)
7 print("Balance as of end of Year 3: $%.2f."%d)

Input Expected Got

10000 Balance as of end of Year 1: $10400.00. Balance as of end of Year 1: $10400.00.


Balance as of end of Year 2: $10816.00. Balance as of end of Year 2: $10816.00.
Balance as of end of Year 3: $11248.64. Balance as of end of Year 3: $11248.64.

20000 Balance as of end of Year 1: $20800.00. Balance as of end of Year 1: $20800.00.


Balance as of end of Year 2: $21632.00. Balance as of end of Year 2: $21632.00.
Balance as of end of Year 3: $22497.28. Balance as of end of Year 3: $22497.28.

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

20
Question 3
Correct

Mark 1.00 out of 1.00

Mr. X's birthday is in next month. This time he is planning to invite N of his friends. He wants to distribute some chocolates to all of his
friends after the party. He went to a shop to buy a packet of chocolates. At the chocolate shop, 4 packets are there with different numbers
of chocolates. He wants to buy such a packet which contains a number of chocolates, which can be distributed equally among all of his
friends. Help Mr. X to buy such a packet.
Input Given:

N-No of friends

P1,P2,P3 AND P4-No of chocolates

OUTPUT:

"True" if he can buy that packet and "False" if he can't buy that packet.
SAMPLE INPUT AND OUTPUT:

25

12

10
9

OUTPUT

True False True False

For example:

Input Result

5 True False True True


25
23
20
10

Answer: (penalty regime: 0 %)


1 N=int(input())
2 P1=int(input())
3 P2=int(input())
4 P3=int(input())
5 P4=int(input())
6 print(P1%N==0, end=" ")
7 print(P2%N==0, end=" ")
8 print(P3%N==0, end=" ")
9 print(P4%N==0, end=" ")

21
Input Expected Got

5 True False True True True False True True


25
23
20
10

4 False True False True False True False True


23
24
21
12

8 True True True True True True True True


64
8
16
32

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

22
Question 4
Correct

Mark 1.00 out of 1.00

Write a python program that takes a integer between 0 and 15 as input and displays the number of '1' s in its binary form.(Hint:use python
bitwise operator.

Sample Input
3
Sample Output:

Explanation:

The binary representation of 3 is 011, hence there are 2 ones in it. so the output is 2.

For example:

Input Result

3 2

Answer: (penalty regime: 0 %)


1 a=int(input())
2 print(bin(a).count("1"))

Input Expected Got

3 2 2

5 2 2

15 4 4

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

23
Question 5

Correct

Mark 1.00 out of 1.00

In London, every year during Dasara there will be a very grand doll show. People try to invent new dolls of different varieties. The best-sold
doll's creator will be awarded with a cash prize. So people broke their heads to create dolls innovatively. Knowing this competition,
[Link] tried to create a doll that sings only when an even number is pressed and the number should not be zero and greater than 100.

IF Lokpaul wins print true, otherwise false.

Sample Input

10
Sample Output

True

Explanation:

Since 10 is an even number and a number between 0 and 100, True is printed

For example:

Input Result

101 False

Answer: (penalty regime: 0 %)


1 a=int(input())
2 a%2
3 print(0<a<100)

Input Expected Got

56 True True

101 False False

-1 False False

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

24
Question 6
Correct

Mark 1.00 out of 1.00

[Link] has been given a problem kindly help him to solve it. The input of the program is either 0 or 1. IF 0 is the input he should display
"C" if 1 is the input it should display "D".There is a constraint that Mr. Ram should use either logical operators or arithmetic operators to
solve the problem, not anything else.

Hint:

Use ASCII values of C and D.

Input Format:
An integer x, 0<=x<=1. .

Output Format:

output a single character "C" or "D"depending on the value of x.


Input 1:
0
Output 1:
C

Input 2:
1

Output 1:
D

For example:

Input Result

0 C

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=ord("C")
3 print(chr(b+a))

25
Input Expected Got

0 C C

1 D D

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

26
Question 7

Correct

Mark 1.00 out of 1.00

Write a program that returns the last digit of the given number. Last digit is being referred to the least significant digit i.e. the digit in the
ones (units) place in the given number.

The last digit should be returned as a positive number.


For example,

if the given number is 197, the last digit is 7


if the given number is -197, the last digit is 7

For example:

Input Result

197 7

-197 7

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=abs(a)
3 c=b%10
4 print(c)

Input Expected Got

197 7 7

-197 7 7

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

27
Question 8
Correct

Mark 1.00 out of 1.00

In the 1800s, the battle of Troy was led by Hercules. He was a superstitious person. He believed that his crew can win the battle only if the
total count of the weapons in hand is in multiple of 3 and the soldiers are in an even number of count. Given the total number of weapons
and the soldier's count, Find whether the battle can be won or not according to Hercules's belief. If the battle can be won print True
otherwise print False.
Input format:

Line 1 has the total number of weapons

Line 2 has the total number of Soldiers.

Output Format:

If the battle can be won print True otherwise print False.


Sample Input:

32

43

Sample Output:'

False

For example:

Input Result

32 False
43

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 print(a%3==0 and b%2==0)

Input Expected Got

32 False False
43

273 True True


7890

800 False False


4590

28
Input Expected Got

6789 True True


32996

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

Question 9
Correct

Mark 10.00 out of 10.00

An online retailer sells two products: widgets and gizmos. Each widget weighs 75 grams. Each gizmo weighs 112 grams. Write a program
that reads the number of widgets and the number of gizmos from the user. Then your program should compute and display the total
weight of the parts.

Sample Input:

10

20
Sample Output:

The total weight of all these widgets and gizmos is 2990 grams.

Answer: (penalty regime: 0 %)


1 w=int(input())
2 g=int(input())
3 x=w*75+g*112
4 print("The total weight of all these widgets and gizmos is %d"%x, end=" ")
5 print("grams.")

Input Expected Got

10 The total weight of all these widgets and gizmos is The total weight of all these widgets and gizmos is
20 2990 grams. 2990 grams.

Passed all tests!

Correct
Marks for this submission: 10.00/10.00.

29
Question 10
Correct

Mark 1.00 out of 1.00

The program that you create for this exercise will begin by reading the cost of a meal ordered at a restaurant from the user. Then your
program will compute the tax and tip for the meal. Use your local tax rate (5 percent) when computing the amount of tax owing. Compute
the tip as 18 percent of the meal amount (without the tax). The output from your program should include the tax amount, the tip amount,
and the grand total for the meal including both the tax and the tip. Format the output so that all of the values are displayed using two
decimal places.
Sample Input

100
Sample Output

The tax is 5.00 and the tip is 18.00, making the total 123.00

For example:

Input Result

100 The tax is 5.00 and the tip is 18.00, making the total 123.00

Answer: (penalty regime: 0 %)


1 cost=float(input())
2 tax=(cost*0.05)
3 tip=(cost*0.18)
4 total=(cost+tax+tip)
5 print("The tax is %.2f"%tax, end=" ")
6 print("and the tip is %.2f"%tip, end=",")
7 print(" making the total %.2f"%total)

Input Expected Got

100 The tax is 5.00 and the tip is 18.00, making the The tax is 5.00 and the tip is 18.00, making the
total 123.00 total 123.00

250 The tax is 12.50 and the tip is 45.00, making the The tax is 12.50 and the tip is 45.00, making the
total 307.50 total 307.50

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week2_MCQ

Jump to...

30 Selection control structures ►


Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Algorithmic Approach: Selection control structures / Week3_Coding

Status Finished
Started Saturday, 22 March 2025, 8:09 AM
Completed Sunday, 23 March 2025, 3:46 PM
Duration 1 day 7 hours
Marks 10.00/10.00
Grade 100.00 out of 100.00

31
Question 1
Correct

Mark 1.00 out of 1.00

Write a program that returns the second last digit of the given number. Second last digit is being referred 10the digit in the tens place in
the given number.

For example, if the given number is 197, the second last digit is 9.
Note1 - The second last digit should be returned as a positive number. i.e. if the given number is -197, the second last digit is 9.

Note2 - If the given number is a single digit number, then the second last digit does not exist. In such cases, the program should return -1.
i.e. if the given number is 5, the second last digit should be returned as -1

For example:

Input Result

197 9

5 -1

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=abs(a)
3 c=(b//10)%10
4 ▼ if (b>=10):
5 print(c)
6 ▼ else:
7 print("-1")

Input Expected Got

197 9 9

-197 9 9

5 -1 -1

123456 5 5

8 -1 -1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

32
Question 2

Correct

Mark 1.00 out of 1.00

Most years have 365 days. However, the time required for the Earth to orbit the Sun is actually slightly more than that. As a result, an extra
day, February 29, is included in some years to correct for this difference. Such years are referred to as leap years. The rules for determining
whether or not a year is a leap year follow:

• Any year that is divisible by 400 is a leap year.

• Of the remaining years, any year that is divisible by 100 is not a leap year.

• Of the remaining years, any year that is divisible by 4 is a leap year.


• All other years are not leap years.

Write a program that reads a year from the user and displays a message indicating whether or not it is a leap year.

Sample Input 1
1900

Sample Output 1
1900 is not a leap year.

Sample Input 2
2000

Sample Output 2

2000 is a leap year.

Answer: (penalty regime: 0 %)


1 a=int(input())
2 ▼ if (a%400==0 and a%4==0):
3 print(a,"is a leap year.")
4 ▼ elif (a%100==0):
5 print(a,"is not a leap year.")

Input Expected Got

1900 1900 is not a leap year. 1900 is not a leap year.

2000 2000 is a leap year. 2000 is a leap year.

2100 2100 is not a leap year. 2100 is not a leap year.

2400 2400 is a leap year. 2400 is a leap year.

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

33
Question 3
Correct

Mark 1.00 out of 1.00

A triangle can be classified based on the lengths of its sides as equilateral, isosceles or scalene. All three sides of an equilateral triangle have
the same length. An isosceles triangle has two sides that are the same length, and a third side that is a different length. If all of the sides
have different lengths then the triangle is scalene.

Write a program that reads the lengths of the three sides of a triangle from the user. Then display a message that states the triangle’s type.

Sample Input 1

60
60

60

Sample Output 1

That's a equilateral triangle

Sample Input 2
40

40

80

Sample Output 2

That's a isosceles triangle


Sample Input 3

50

60

70

Sample Output 3
That's a scalene triangle

For example:

Input Result

60 That's a equilateral triangle


60
60

40 That's a isosceles triangle


40
80

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 c=int(input())
4 ▼ if (a==b==c):
5 print("That's a equilateral triangle")
6 ▼ elif (a==b<c):
7 print("That's a isosceles triangle")
8 ▼ else:
9 print("That's a scalene triangle")

34
Input Expected Got

60 That's a equilateral triangle That's a equilateral triangle


60
60

40 That's a isosceles triangle That's a isosceles triangle


40
80

50 That's a scalene triangle That's a scalene triangle


60
70

50 That's a isosceles triangle That's a isosceles triangle


50
80

10 That's a equilateral triangle That's a equilateral triangle


10
10

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

35
Question 4
Correct

Mark 1.00 out of 1.00

The Chinese zodiac assigns animals to years in a 12 year cycle. One 12 year cycle is shown in the table below. The pattern repeats from
there, with 2012 being another year of the dragon, and 1999 being another year of the hare.

Year Animal
2000 Dragon

2001 Snake

2002 Horse

2003 Sheep
2004 Monkey

2005 Rooster

2006 Dog

2007 Pig

2008 Rat
2009 Ox

2010 Tiger

2011 Hare

Write a program that reads a year from the user and displays the animal associated with that year. Your program should work correctly for
any year greater than or equal to zero, not just the ones listed in the table.
Sample Input 1

2010

Sample Output 1

2010 is the year of the Tiger.

Sample Input 2
2020

Sample Output 2

2020 is the year of the Rat.

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=(a-2000)%12
3 ▼ if(b==0):
4 print(a,"is the year of the Dragon.")
5 ▼ elif(b==1):
6 print(a,"is the year of the Snake.")
7 ▼ elif(b==2):
8 print(a,"is the year of the Horse.")
9 ▼ elif(b==3):
10 print(a,"is the year of the Sheep.")
11 ▼ elif(b==4):
12 print(a,"is the year of the Monkey.")
13 ▼ elif(b==5):
14 print(a,"is the year of the Rooster.")
15 ▼ elif(b==6):
16 print(a,"is the year of the Dog.")
17 ▼ elif(b==7):
18 print(a,"is the year of the Pig.")
19 ▼ elif(b==8):
20 print(a,"is the year of the Rat.")
21 ▼ elif(b==9):
22 print(a,"is the year of the Ox.")
23 ▼ elif(b==10):
24 print(a,"is the year of the Tiger.")
25 ▼ elif(b==11):
26 print(a,"is the year of the Hare.")

36
Input Expected Got

2010 2010 is the year of the Tiger. 2010 is the year of the Tiger.

2020 2020 is the year of the Rat. 2020 is the year of the Rat.

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

37
Question 5
Correct

Mark 1.00 out of 1.00

In this exercise you will create a program that reads a letter of the alphabet from the user. If the user enters a, e, i, o or u then your program
should display a message indicating that the entered letter is a vowel. If the user enters y then your program should display a message
indicating that sometimes y is a vowel, and sometimes y is a consonant. Otherwise your program should display a message indicating that
the letter is a consonant.
Sample Input 1

Sample Output 1

It's a vowel.

Sample Input 2
y

Sample Output 2

Sometimes it's a vowel... Sometimes it's a consonant.

Sample Input3

Sample Output 3

It's a consonant.

For example:

Input Result

y Sometimes it's a vowel... Sometimes it's a consonant.

c It's a consonant.

Answer: (penalty regime: 0 %)


1 a=input()
2 ▼ if (a=="a" or a=="e" or a=="i" or a=="o" or a=="u"):
3 print("It's a vowel.")
4 ▼ elif (a=="y"):
5 print("Sometimes it's a vowel... Sometimes it's a consonant.")
6 ▼ else:
7 print("It's a consonant.")

Input Expected Got

i It's a vowel. It's a vowel.

y Sometimes it's a vowel... Sometimes it's a Sometimes it's a vowel... Sometimes it's a
consonant. consonant.

c It's a consonant. It's a consonant.

38
Input Expected Got

e It's a vowel. It's a vowel.

r It's a consonant. It's a consonant.

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

39
Question 6
Correct

Mark 1.00 out of 1.00

Write a program to calculate and print the Electricity bill where the unit consumed by the user is given from test case. It prints the total
amount the customer has to pay. The charge are as follows:

Unit Charge / Unit


Upto 199 @1.20

200 and above but less than 400 @1.50

400 and above but less than 600 @1.80

600 and above @2.00

If bill exceeds Rs.400 then a surcharge of 15% will be charged and the minimum bill should be of Rs.100/-
Sample Test Cases

Test Case 1
Input

50

Output
100.00

Test Case 2

Input

300

Output
517.50

For example:

Input Result

100.00 120.00

Answer: (penalty regime: 0 %)


1 a=float(input())
2 ▼ if(a<=199):
3 b=a*1.20
4 ▼ elif(a<400):
5 b=a*1.50
6 ▼ elif(a<600):
7 b=a*1.80
8 ▼ else:
9 b=a*2.00
10 ▼ if(b>400):
11 b=b+b*(15/100)
12 ▼ if(b<100):
13 b=100.00
14 print("%.2f"%b)

Input Expected Got

50 100.00 100.00
40
Input Expected Got

100.00 120.00 120.00

500 1035.00 1035.00

700 1610.00 1610.00

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

41
Question 7
Correct

Mark 1.00 out of 1.00

Write a program to find the eligibility of admission for a professional course based on the following criteria:
Marks in Maths >= 65

Marks in Physics >= 55

Marks in Chemistry >= 50

Or

Total in all three subjects >= 180

Sample Test Cases

Test Case 1

Input
70
60

80

Output

The candidate is eligible

Test Case 2

Input

50
80
80

Output
The candidate is eligible

Test Case 3

Input

50
60
40

Output

The candidate is not eligible

For example:

Input Result

70 The candidate is eligible


60
80

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 c=int(input())
4 d=a+b+c
5 ▼ if (d>=180):
6 print("The candidate is eligible")
7 ▼ else:
8 print("The candidate is not eligible")

42
Input Expected Got

70 The candidate is eligible The candidate is eligible


60
80

50 The candidate is eligible The candidate is eligible


80
80

50 The candidate is not eligible The candidate is not eligible


60
40

20 The candidate is not eligible The candidate is not eligible


10
25

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

43
Question 8
Correct

Mark 1.00 out of 1.00

Three numbers form a Pythagorean triple if the sum of squares of two numbers is equal to the square of the third.
For example, 3, 5 and 4 form a Pythagorean triple, since 3*3 + 4*4 = 25 = 5*5

You are given three integers, a, b, and c. They need not be given in increasing order. If they form a Pythagorean triple, then print "yes",
otherwise, print "no". Please note that the output message is in small letters.

Sample Input
3

4
Sample Output

yes

Sample Test Cases

Test Case 1

Input
3
5

Output

yes

Test Case 2

Input

5
8

2
Output

no

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 c=int(input())
4 ▼ if (a**2+b**2==c**2):
5 print("yes")
6 ▼ elif (b**2+c**2==a**2):
7 print("yes")
8 ▼ elif (c**2+a**2==b**2):
9 print("yes")
10 ▼ else:
11 print("no")

44
Input Expected Got

3 yes yes
5
4

5 no no
8
2

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

45
Question 9
Correct

Mark 1.00 out of 1.00

IN / OUT

Ms. Sita, the faculty handling programming lab for you is very strict. Your seniors have told you that she will not allow you to enter the
week's lab if you have not completed atleast half the number of problems given last week. Many of you didn't understand this statement
and so they requested the good programmers from your batch to write a program to find whether a student will be allowed into a week's
lab given the number of problems given last week and the number of problems solved by the student in that week.

Input Format:

Input consists of 2 integers.

The first integer corresponds to the number of problems given and the second integer corresponds to the number of problems solved.

Output Format:

Output consists of the string “IN” or “OUT”.

Sample Input and Output:

Input

Output

OUT

For example:

Input Result

8 OUT
3

Answer: (penalty regime: 0 %)


1 a=int(input())
2 b=int(input())
3 c=a//2
4 ▼ if (b>=c):
5 print("IN")
6 ▼ else:
7 print("OUT")

46
Input Expected Got

8 OUT OUT
3

8 IN IN
5

20 OUT OUT
9

50 IN IN
31

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

47
Question 10
Correct

Mark 1.00 out of 1.00

The length of a month varies from 28 to 31 days. In this exercise you will create a program that reads the name of a month from the user as
a string. Then your program should display the number of days in that month. Display “28 or 29 days” for February so that leap years are
addressed.

Sample Input 1

February

Sample Output 1
February has 28 or 29 days in it.
Sample Input 2

March

Sample Output 2
March has 31 days in it.
Sample Input 3

April

Sample Output 3

April has 30 days in it.

For example:

Input Result

February February has 28 or 29 days in it.

Answer: (penalty regime: 0 %)


1 a=input()
2 ▼ if (a=="January" or a=="March" or a=="May" or a=="July" or a=="August" or a=="October" or a=="December"):
3 print(a,"has 31 days in it.")
4 ▼ elif (a=="February"):
5 print(a,"has 28 or 29 days in it.")
6 ▼ else:
7 print(a,"has 30 days in it.")

Input Expected Got

February February has 28 or 29 days in it. February has 28 or 29 days in it.

March March has 31 days in it. March has 31 days in it.

April April has 30 days in it. April has 30 days in it.

May May has 31 days in it. May has 31 days in it.

48
Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week3_MCQ

Jump to...

Iteration control structures ►

49
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Algorithmic Approach: Iteration control structures. / Week4_Coding

Status Finished
Started Saturday, 29 March 2025, 6:11 AM
Completed Thursday, 3 April 2025, 10:02 PM
Duration 5 days 15 hours
Marks 10.00/10.00
Grade 100.00 out of 100.00

50
Question 1
Correct

Mark 1.00 out of 1.00

Given a positive integer N, check whether it can be represented as a product of single digit numbers.
Input Format:

Single Integer input.

Output Format:

Output displays Yes if condition satisfies else prints No.


Example Input:
14

Output:

Yes

Example Input:
13

Output:

No

Answer: (penalty regime: 0 %)


1 n=int(input())
2 a="No"
3 ▼ for i in range(1,10):
4 ▼ for j in range(1,10):
5 ▼ if i*j==n:
6 a="Yes"
7 break
8 print(a)

Input Expected Got

14 Yes Yes

13 No No

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

51
Question 2
Correct

Mark 1.00 out of 1.00

Write a program to return the nth number in the fibonacci series.


The value of N will be passed to the program as input.

NOTE: Fibonacci series looks like –

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, . . . and so on.

i.e. Fibonacci series starts with 0 and 1, and continues generating the next number as the sum of the previous two numbers.

• first Fibonacci number is 0,

• second Fibonacci number is 1,

• third Fibonacci number is 1,

• fourth Fibonacci number is 2,


• fifth Fibonacci number is 3,

• sixth Fibonacci number is 5,

• seventh Fibonacci number is 8, and so on.

For example:

Input Result

1 0

4 2

7 8

Answer: (penalty regime: 0 %)


1 n=int(input())
2 ▼ if (n==1):
print("0")
▼ elif (n==2):
print("1")
▼ else:
7 a,b=0,1
▼ for i in range(n-2):
a,b=b,a+b
print(b)

Input Expected Got

1 0 0

4 2 2

7 8 8

Passed all tests!

Correct

Marks for this submission: 1.00/1.00.


52
Question 3

Correct

Mark 1.00 out of 1.00

Write a program to find the count of non-repeated digits in a given number N. The number will be passed to the program as an input of
type int.

Assumption: The input number will be a positive integer number >= 1 and <= 25000.
Some examples are as below.

If the given number is 292, the program should return 1 because there is only 1 non-repeated digit '9' in this number
If the given number is 1015, the program should return 2 because there are 2 non-repeated digits in this number, '0', and '5'.

If the given number is 108, the program should return 3 because there are 3 non-repeated digits in this number, '1', '0', and '8'.

If the given number is 22, the function should return 0 because there are NO non-repeated digits in this number.

For example:

Input Result

292 1

1015 2

108 3

22 0

Answer: (penalty regime: 0 %)


1 a=input()
2 b=[]
3 ▼ for i in a:
4 ▼ if ([Link](i)==1):
5 [Link](i)
6 print(len(b))

Input Expected Got

292 1 1

1015 2 2

108 3 3

22 0 0

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

53
Question 4
Correct

Mark 1.00 out of 1.00

Given an integer N, check whether N the given number can be made a perfect square after adding to it.

Input Format:

Single integer input.

Output Format:

Yes or No.

Example Input:

24
Output:

Yes

Example Input:

26

Output:

No

For example:

Input Result

24 Yes

Answer: (penalty regime: 0 %)


1 a=int(input())+1
2 b=int(a**(0.5))
3 ▼ if (a==b**2):
4 c="Yes"
5 ▼ else:
6 c="No"
7 print(c)

Input Expected Got

24 Yes Yes

26 No No

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

54
Question 5
Correct

Mark 1.00 out of 1.00

Write a program that finds whether the given number N is Prime or not.
If the number is prime, the program should return 2 else it must return 1.
Assumption: 2 <= N <=5000, where N is the given number.

Example1: if the given number N is 7, the method must return 2


Example2: if the given number N is 10, the method must return 1

For example:

Input Result

7 2

10 1

Answer: (penalty regime: 0 %)


1 n=int(input())
2 a=2
3 ▼ for i in range(2,n):
4 ▼ if (n%i==0):
5 a=1
6 break
7 print(a)

Input Expected Got

7 2 2

10 1 1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

55
Question 6
Correct

Mark 1.00 out of 1.00

A Number is said to be Disarium number when the sum of its digit raised to the power of their respective positions becomes equal to the
number itself. Write a program to print number is Disarium or not.

Input Format:

Single Integer Input from stdin.

Output Format:

Yes or No.

Example Input:

175
Output:

Yes

Explanation
1^1 + 7^2 +5^3 = 175

Example Input:

123

Output:

No

For example:

Input Result

175 Yes

123 No

Answer: (penalty regime: 0 %)


n=int(input())
a=n
sum=0
length=len(str(n))
▼ while a>0:
digit=a%10
sum+=digit**length
length-=1
a//=10
▼ if sum==n:
print("Yes")
▼ else:
print("No")

Input Expected Got

175 Yes Yes

123 No No

Passed all tests!

Correct

Marks for this submission: 1.00/1.00.


56
Question 7
Correct

Mark 1.00 out of 1.00

Write a program to find the count of unique digits in a given number N. The number will be passed to the program as an input of type int.
Assumption: The input number will be a positive integer number >= 1 and <= 25000.
For e.g.

If the given number is 292, the program should return 2 because there are only 2 unique digits '2' and '9' in this number

If the given number is 1015, the program should return 3 because there are 3 unique digits in this number, '1', '0', and '5'.

For example:

Input Result

292 2

1015 3

Answer: (penalty regime: 0 %)


1 a=int(input())
2 n=len(set(str(a)))
3 print(n)

Input Expected Got

292 2 2

1015 3 3

123 3 3

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

57
Question 8
Correct

Mark 1.00 out of 1.00

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For
example,

5! = 5 x 4 x 3 x 2 x 1 = 120
4! = 4 x 3 x 2 x 1 = 24
9! = 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 362880

Write a program to find the factorial of a given number.

The given number will be passed to the program as an input of type int.

The program is expected to calculate the factorial of the given number and return it as an int type.

Assumptions for this program:

The given input number will always be greater than or equal to 1.

Due to the range supported by int. the input numbers will range from 1 to 12.

For example:

Input Result

5 120

4 24

9 362880

Answer: (penalty regime: 0 %)


1 n=int(input())
2 factorial=1
3 ▼ for i in range(1,n+1):
4 factorial*=i
5 print(factorial)

Input Expected Got

5 120 120

4 24 24

9 362880 362880

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

58
Question 9
Correct

Mark 1.00 out of 1.00

Write a program to find the sum of the series 1 +11 + 111 + 1111 + . . . + n terms (n will be given as input from the user and sum will be
the output)

Sample Test Cases


Test Case 1

Input

Output

1234

Test Case 2

Input
6
Output

123456

Answer: (penalty regime: 0 %)


1 n=int(input())
2 ans=0
3 term=0
4 ▼ for i in range(n):
5 term=term*10+1
6 ans+=term
7 print(ans)

Input Expected Got

4 1234 1234

6 123456 123456

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

59
Question 10
Correct

Mark 1.00 out of 1.00

Given a number N, find the next perfect square greater than N.


Input Format:

Integer input from stdin.

Output Format:

Perfect square greater than N.


Example Input:

10

Output:

16

Answer: (penalty regime: 0 %)


1 n=int(input())
2 i=1
3 ▼ while True:
4 b=i*i
5 ▼ if b>n:
6 print(b)
7 break
8 i+=1

Input Expected Got

10 16 16

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week4_MCQ

Jump to...

Functions ►

60
Dashbo… / My cour… / GE23231/GE23233-PUP/PSPP-… / Functions: Built-in functions, User-defined functions, Recursive f… / Week 5_Cod…

Status Finished
Started Saturday, 5 April 2025, 5:09 AM
Completed Monday, 7 April 2025, 9:41 AM
Duration 2 days 4 hours
Marks 5.00/5.00
Grade 100.00 out of 100.00

61
Question 1
Correct

Mark 1.00 out of 1.00

An automorphic number is a number whose square ends with the number itself.

For example, 5 is an automorphic number because 5*5 =25. The last digit is 5 which same

as the given number.


If the number is not valid, it should display “Invalid input”.

If it is an automorphic number display “Automorphic” else display “Not Automorphic”.

Input Format:

Take a Integer from Stdin Output Format: Print Automorphic if given number is Automorphic number,otherwise Not Automorphic Example
input: 5 Output: Automorphic Example input: 25 Output: Automorphic Example input: 7 Output: Not Automorphic

For example:

Test Result

print(automorphic(5)) Automorphic

Answer: (penalty regime: 0 %)

Reset answer

1 ▼ def automorphic(n):
2 a=n**2
3 b=a%10
4 ▼ if (b==n):
5 return("Automorphic")
6 ▼ else:
7 return("Not Automorphic")

Test Expected Got

print(automorphic(5)) Automorphic Automorphic

print(automorphic(7)) Not Automorphic Not Automorphic

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

62
Question 2

Correct

Mark 1.00 out of 1.00

complete function to implement coin change making problem i.e. finding the minimum

number of coins of certain denominations that add up to given amount of money.

The only available coins are of values 1, 2, 3, 4


Input Format:

Integer input from stdin.

Output Format:

return the minimum number of coins required to meet the given target.

Example Input:
16

Output:

Explanation:

We need only 4 coins of value 4 each


Example Input:

25
Output:

Explanation:
We need 6 coins of 4 value, and 1 coin of 1 value

Answer: (penalty regime: 0 %)

Reset answer

▼ def coinChange(n):
count=0
3 ▼ for i in [4,3,2,1]:
4 ▼ if (n>=i):
num=n//i
count+=num
n-=num*i
return count

Test Expected Got

print(coinChange(16)) 4 4

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

63
Question 3
Correct

Mark 1.00 out of 1.00

An abundant number is a number for which the sum of its proper divisors is greater than

the number itself. Proper divisors of the number are those that are strictly lesser than the number.

Input Format:

Take input an integer from stdin


Output Format:

Return Yes if given number is Abundant. Otherwise, print No


Example input:

12

Output:
Yes
Explanation

The proper divisors of 12 are: 1, 2, 3, 4, 6, whose sum is 1 + 2 + 3 + 4 + 6 = 16. Since sum of

proper divisors is greater than the given number, 12 is an abundant number.


Example input:
13

Output:

No
Explanation

The proper divisors of 13 is: 1, whose sum is 1. Since sum of proper divisors is not greater
than the given number, 13 is not an abundant number.

For example:

Test Result

print(abundant(12)) Yes

print(abundant(13)) No

Answer: (penalty regime: 0 %)

Reset answer

▼ def abundant(n):
sum=0
▼ for i in range(1,n):
▼ if (n%i==0):
sum+=i
▼ if (sum>n):
return "Yes"
▼ else:
return "No"

64
Test Expected Got

print(abundant(12)) Yes Yes

print(abundant(13)) No No

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

65
Question 4

Correct

Mark 1.00 out of 1.00

Given a number with maximum of 100 digits as input, find the difference between the sum

of odd and even position digits.

Input Format:
Take a number in the form of String from stdin.
Output Format:

Print the difference between sum of even and odd digits

Example input:
1453
Output:

Explanation:

Here, sum of even digits is 4 + 3 = 7

sum of odd digits is 1 + 5 = 6.


Difference is 1.

Note that we are always taking absolute difference

Answer: (penalty regime: 0 %)

Reset answer

▼ def differenceSum(n):
evensum=0
oddsum=0
temp=n
▼ while (n>0):
6 a=n%10
evensum+=a
n=n//100
n=temp
n=n//10
▼ while (n>0):
12 b=n%10
oddsum+=b
n=n//100
return abs(evensum-oddsum)

Test Expected Got

print(differenceSum(1453)) 1 1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

66
Question 5
Correct

Mark 1.00 out of 1.00

Write a code to check whether product of digits at even places is divisible by sum of digits

at odd place of a positive integer.

Input Format:
Take an input integer from stdin.

Output Format:

Print TRUE or FALSE.

Example Input:

1256
Output:

TRUE

Example Input:

1595

Output:
FALSE

For example:

Test Result

print(productDigits(1256)) True

print(productDigits(1595)) False

Answer: (penalty regime: 0 %)

Reset answer

1 ▼ def productDigits(n):
2 product=1
3 sum=0
4 temp=n
5 ▼ while (n>0):
6 a=n%10
7 product*=a
8 n=n//100
9 n=temp
10 n=n//10
11 ▼ while n>0:
12 b=n%10
13 sum+=b
14 n=n//100
15 ▼ if(product%sum==0):
16 return "True"
17 ▼ else:
18 return "False"

Test Expected Got

print(productDigits(1256)) True True

print(productDigits(1595)) False False

Passed all tests!

Correct
67
Marks for this submission: 1.00/1.00.

◄ Week 5_MCQ

Jump to...

Strings ►

68
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Experiments based on Strings and its operations. / Week 6_Coding

Status Finished
Started Wednesday, 23 April 2025, 6:25 PM
Completed Saturday, 3 May 2025, 8:08 AM
Duration 9 days 13 hours
Marks 10.00/10.00
Grade 100.00 out of 100.00

69
Question 1
Correct

Mark 1.00 out of 1.00

Write a program that takes as input a string (sentence), and returns its second word in uppercase.
For example:

If input is “Wipro Technologies Bangalore” the function should return “TECHNOLOGIES”

If input is “Hello World” the function should return “WORLD”


If input is “Hello” the program should return “LESS”

NOTE 1: If input is a sentence with less than 2 words, the program should return the word “LESS”.

NOTE 2: The result should have no leading or trailing spaces.

For example:

Input Result

Wipro Technologies Bangalore TECHNOLOGIES

Hello World WORLD

Hello LESS

Answer: (penalty regime: 0 %)


1 a=input().split()
2 ▼ if (len(a)==1):
3 print("LESS")
4 ▼ else:
5 print(a[1].upper())

Input Expected Got

Wipro Technologies Bangalore TECHNOLOGIES TECHNOLOGIES

Hello World WORLD WORLD

Hello LESS LESS

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

70
Question 2
Correct

Mark 1.00 out of 1.00

Reverse a string without affecting special characters


Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special
characters.
Input:
A&B
Output:
B&A
Explanation: As we ignore '&' and
As we ignore '&' and then reverse, so answer is "B&A".

For example:

Input Result

A&x# x&A#

Answer: (penalty regime: 0 %)


1 a=input().strip()
2 a_list=list(a)
3 alphabets=[]
4 ▼ for j in a:
5 ▼ if [Link]():
6 [Link](j)
7 [Link]()
8 index=0
9 ▼ for i in range(len(a_list)):
10 ▼ if a_list[i].isalpha():
11 a_list[i]=alphabets[index]
12 index+=1
13 print("".join(a_list))

Input Expected Got

A&B B&A B&A

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

71
Question 3

Correct

Mark 1.00 out of 1.00

In this exercise, you will create a program that reads words from the user until the user enters a blank line. After the user enters a blank line
your program should display each word entered by the user exactly once. The words should be displayed in the same order that they were
first entered. For example, if the user enters:

first
second
first
third
second

then your program should display:

first

second
third

Answer: (penalty regime: 0 %)


1 a=input()
2 b=input()
3 c=input()
4 d=input()
5 e=input()
6 print(a)
7 ▼ if (b==a):
8 pass
9 ▼ else:
10 print(b)
11 ▼ if (c==a or c==b):
12 pass
13 ▼ else:
14 print(c)
15 ▼ if (d==a or d==b or d==c):
16 pass
17 ▼ else:
18 print(d)
19 ▼ if (e==a or e==b or e==c or e==d):
20 pass
21 ▼ else:
22 print(e)

Input Expected Got

first first first


second second second
first third third
third
second

rec rec rec


cse cse cse
it it it
rec
cse

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

72
Question 4

Correct

Mark 1.00 out of 1.00

Given two Strings s1 and s2, remove all the characters from s1 which is present in s2.

Constraints

1<= string length <= 200

Sample Input 1

experience
enc

Sample Output 1

xpri

Answer: (penalty regime: 0 %)


1 s1=input()
2 s2=input()
3 ▼ for ch in s1:
4 ▼ if ch in s2:
5 pass
6 ▼ else:
7 print(ch,end="")

Input Expected Got

experience xpri xpri


enc

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

73
Question 5
Correct

Mark 1.00 out of 1.00

Assume that the given string has enough memory.

Don't use any extra space(IN-PLACE)

Sample Input 1

a2b4c6

Sample Output 1

aabbbbcccccc

Answer: (penalty regime: 0 %)


1 s=input()
2 result=[]
3 i=0
4 ▼ while i<len(s):
5 ▼ if s[i].isalpha:
6 letter=s[i]
7 repeat=0
8 i+=1
9 ▼ while i<len(s) and s[i].isdigit():
10 repeat=(repeat*10)+int(s[i])
11 i+=1
12 [Link](letter*repeat)
13 ▼ else:
14 i+=1
15 expand=''.join(result)
16 print(expand)

Input Expected Got

a2b4c6 aabbbbcccccc aabbbbcccccc

a12b3d4 aaaaaaaaaaaabbbdddd aaaaaaaaaaaabbbdddd

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

74
Question 6
Correct

Mark 1.00 out of 1.00

String should contain only the words are not palindrome.

Sample Input 1

Malayalam is my mother tongue

Sample Output 1

is my mother tongue

Answer: (penalty regime: 0 %)


1 a=input().lower()
2 b=[Link]()
3 ▼ for i in b:
4 ▼ if i == i[::-1]:
5 pass
6 ▼ else:
7 print(i,end=" ")

Input Expected Got

Malayalam is my mother tongue is my mother tongue is my mother tongue

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

75
Question 7
Correct

Mark 1.00 out of 1.00

Write a python program to count all letters, digits, and special symbols respectively from a given string

For example:

Input Result

rec@123 3
3
1

Answer: (penalty regime: 0 %)


1 a=input()
2 letters=0
3 digits=0
4 symbols=0
5 ▼ for i in a:
6 ▼ if ([Link]()):
7 letters+=1
8 ▼ elif ([Link]()):
9 digits+=1
10 ▼ else:
11 symbols+=1
12 print(letters)
13 print(digits)
14 print(symbols)

Input Expected Got

rec@123 3 3
3 3
1 1

P@#yn26at^&i5ve 8 8
3 3
4 4

abc@12& 3 3
2 2
2 2

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

76
Question 8
Correct

Mark 1.00 out of 1.00

Given a string S which is of the format USERNAME@[Link], the program must print the EXTENSION, DOMAIN, USERNAME in
the reverse order.

Input Format:
The first line contains S.

Output Format:

The first line contains EXTENSION.


The second line contains DOMAIN.
The third line contains USERNAME.

Boundary Condition:
1 <= Length of S <= 100

Example Input/Output 1:

Input:

abcd@[Link]

Output:

com
gmail
abcd

Answer: (penalty regime: 0 %)


1 a=input()
2 b=[Link](".")
3 print(a[b+1:])
4 c=[Link](".")
5 d=c[0]
6 e=[Link]("@")
7 print(d[e+1:])
8 print(d[:e])

Input Expected Got

abcd@[Link] com com


gmail gmail
abcd abcd

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.
77
Question 9

Correct

Mark 1.00 out of 1.00

Write a program to check if two strings are balanced. For example, strings s1 and s2 are balanced if all the characters in the s1 are present in
s2. The character’s position doesn’t matter. If balanced display as "true" ,otherwise "false".

For example:

Input Result

Yn True
PYnative

Answer: (penalty regime: 0 %)


1 s1=input()
2 s2=input()
3 flag=True
4 ▼ for i in s1:
5 ▼ if i not in s2:
6 flag=False
7 break
8 print(flag)

Input Expected Got

Yn True True
PYnative

Ynf False False


PYnative

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

78
Question 10
Correct

Mark 1.00 out of 1.00

Two string values S1, S2 are passed as the input. The program must print first N characters present in S1 which are also present in S2.
Input Format:

The first line contains S1.


The second line contains S2.
The third line contains N.

Output Format:
The first line contains the N characters present in S1 which are also present in S2.

Boundary Conditions:

2 <= N <= 10
2 <= Length of S1, S2 <= 1000

Example Input/Output 1:

Input:

abcbde
cdefghbb
3

Output:

bcd

Note:

b occurs twice in common but must be printed only once.

Answer: (penalty regime: 0 %)


1 s1=input()
2 s2=input()
3 N=int(input())
4 s3=""
5 ▼ for i in s1:
6 ▼ if i in s2 and i not in s3:
7 s3+=i
8 ▼ if len(s3)==N:
9 break
10 print(s3)

Input Expected Got

abcbde bcd bcd


cdefghbb
3

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week 6_MCQ

Jump to...

List ►
79
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Experiments based on Lists and its operations. / Week 7_Coding

Status Finished
Started Friday, 2 May 2025, 5:30 PM
Completed Wednesday, 7 May 2025, 7:01 PM
Duration 5 days 1 hour
Marks 10.00/10.00
Grade 100.00 out of 100.00

80
Question 1
Correct

Mark 1.00 out of 1.00

Consider a program to insert an element / item in the sorted array. Complete the logic by filling up required code in editable
section. Consider an array of size 10. The eleventh item is the data is to be inserted.

Sample Test Cases

Test Case 1

Input

1
3
4
5
6
7
8
9
10
11
2

Output

ITEM to be inserted:2
After insertion array is:
1
2
3
4
5
6
7
8
9
10
11

Test Case 2

Input

11
22
33
55
66
77
88
99
110
120
44

Output

ITEM to be inserted:44
After insertion array is:
11
22
33
44
81
55
66
77
88
99
110
120

Answer: (penalty regime: 0 %)


1 l=[]
2 ▼ for x in range(10):
3 [Link](int(input()))
4 a=int(input())
5 print("ITEM to be inserted:",end="")
6 print(a)
7 i=0
8 ▼ while i>len(l) and l[i]<a:
9 i+=1
10 [Link](i,a)
11 [Link]()
12 print("After insertion array is:")
13 ▼ for j in l:
14 print(j)

Input Expected Got

1 ITEM to be inserted:2 ITEM to be inserted:2


3 After insertion array is: After insertion array is:
4 1 1
5 2 2
6 3 3
7 4 4
8 5 5
9 6 6
10 7 7
11 8 8
2 9 9
10 10
11 11

11 ITEM to be inserted:44 ITEM to be inserted:44


22 After insertion array is: After insertion array is:
33 11 11
55 22 22
66 33 33
77 44 44
88 55 55
99 66 66
110 77 77
120 88 88
44 99 99
110 110
120 120

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

82
Question 2
Correct

Mark 1.00 out of 1.00

Program to print all the distinct elements in an array. Distinct elements are nothing but the unique (non-duplicate) elements present in the
given array.

Input Format:

First line take an Integer input from stdin which is array length n.

Second line take n Integers which is inputs of array.


Output Format:

Print the Distinct Elements in Array in single line which is space Separated

Example Input:

2
3

Output:

1234

Example Input:

1
2

Output:

123

For example:

Input Result

5 1 2 3 4
1
2
2
3
4

6 1 2 3
1
1
2
2
3
3

Answer: (penalty regime: 0 %)


1 n=int(input())
2 l=[]
3 ▼ for x in range(n):
4 [Link](int(input()))
5 m=[]
6 for i in l: 83
7 ▼ if i not in m:
8 [Link](i)
▼ for j in m:
print(j, end=" ")

Input Expected Got

5 1 2 3 4 1 2 3 4
1
2
2
3
4

6 1 2 3 1 2 3
1
1
2
2
3
3

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

84
Question 3
Correct

Mark 1.00 out of 1.00

Complete the program to count frequency of each element of an array. Frequency of a particular element will be printed once.

Sample Test Cases

Test Case 1

Input

7
23
45
23
56
45
23
40

Output

23 occurs 3 times
45 occurs 2 times
56 occurs 1 times
40 occurs 1 times

Answer: (penalty regime: 0 %)


1 n=int(input())
2 l=[]
3 ▼ for x in range(n):
4 [Link](int(input()))
5 ▼ for i in range(n):
6 ▼ if l[i] not in l[0:i]:
7 count=0
8 ▼ for j in range(n):
9 ▼ if l[i]==l[j]:
10 count+=1
11 print(l[i],"occurs",count,"times")

Input Expected Got

7 23 occurs 3 times 23 occurs 3 times


23 45 occurs 2 times 45 occurs 2 times
45 56 occurs 1 times 56 occurs 1 times
23 40 occurs 1 times 40 occurs 1 times
56
45
23
40

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.
85
Question 4
Correct

Mark 1.00 out of 1.00

Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the
right are equal. The array may not be reordered.

Example

arr=[1,2,3,4,6]

· the sum of the first three elements, 1+2+3=6. The value of the last element is 6.
· Using zero based indexing, arr[3]=4 is the pivot between the two subarrays.

· The index of the pivot is 3.

Constraints

· 3 ≤ n ≤ 105

· 1 ≤ arr[i] ≤ 2 × 104, where 0 ≤ i < n

· It is guaranteed that a solution always exists.

The first line contains an integer n, the size of the array arr.
Each of the next n lines contains an integer, arr[i], where 0 ≤ i < n.

Sample Case 0

Sample Input 0

3
3

Sample Output 0

Explanation 0

· The sum of the first two elements, 1+2=3. The value of the last element is 3.

· Using zero based indexing, arr[2]=3 is the pivot between the two subarrays.
· The index of the pivot is 2.

Sample Case 1

Sample Input 1

3
1

Sample Output 1

Explanation 1

· The first and last elements are equal to 1.

· Using zero based indexing, arr[1]=2 is the pivot between the two subarrays.
· The index of the pivot is 1.

For example:

86
Input Result

4 2
1
2
3
3

3 1
1
2
1

Answer: (penalty regime: 0 %)


1 n=int(input())
2 l=[]
3 ▼ for x in range(n):
4 [Link](int(input()))
5 total=sum(l)
6 leftsum=0
7 ▼ for i in range(n):
8 rightsum=total-leftsum-l[i]
9 ▼ if leftsum==rightsum:
10 print(i)
11 break
12 leftsum+=l[i]

Input Expected Got

4 2 2
1
2
3
3

3 1 1
1
2
1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

87
Question 5
Correct

Mark 1.00 out of 1.00

Write a program to print all the locations at which a particular element (taken as input) is found in a list and also print the total
number of times it occurs in the list. The location starts from 1.

For example, if there are 4 elements in the array:

5
6
5
7

If the element to search is 5 then the output will be:

5 is present at location 1
5 is present at location 3
5 is present 2 times in the array.

Sample Test Cases

Test Case 1

Input

4
5
6
5
7
5

Output

5 is present at location 1.
5 is present at location 3.
5 is present 2 times in the array.

Test Case 2

Input

5
67
80
45
97
100
50

Output

50 is not present in the array.

Answer: (penalty regime: 0 %)


1 n=int(input())
2 l=[]
3 ▼ for x in range(n):
4 [Link](int(input()))
5 a=int(input())
6 count=0
7 ▼ for i in range(n):
8 ▼ if l[i]==a:
9 print(a, "is present at location", i+1, end="")
10 print(".")
88
12 ▼ if count>0:
13 print(a, "is present", count, "times in the array.")
14 ▼ else:
15 print(a, "is not present in the array.")

Input Expected Got

4 5 is present at location 1. 5 is present at location 1.


5 5 is present at location 3. 5 is present at location 3.
6 5 is present 2 times in the array. 5 is present 2 times in the array.
5
7
5

5 50 is not present in the array. 50 is not present in the array.


67
80
45
97
100
50

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

89
Question 6
Correct

Mark 1.00 out of 1.00

Write a Python program to Zip two given lists of lists.

Input:

m : row size
n: column size

list1 and list 2 : Two lists

Output

Zipped List : List which combined both list1 and list2

Sample test case

Sample input

2
2
1

7
2

8
Sample Output

[[1, 3, 2, 4], [5, 7, 6, 8]]

Answer: (penalty regime: 0 %)


1 m=int(input())
2 n=int(input())
3 l1=[]
4 l2=[]
5 ▼ for x in range(m):
6 ▼ for y in range(n):
7 [Link](int(input()))
8 ▼ for z in range(n):
9 [Link](int(input()))
10 zip=[]
11 [Link](l1)
12 [Link](l2)
13 print(zip)

90
Input Expected Got

2 [[1, 2, 5, 6], [3, 4, 7, 8]] [[1, 2, 5, 6], [3, 4, 7, 8]]


2
1
2
3
4
5
6
7
8

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

91
Question 7
Correct

Mark 1.00 out of 1.00

Write a Python program to check if a given list is strictly increasing or not. Moreover, If removing only one element from the list results in a
strictly increasing list, we still consider the list true

Input:

n : Number of elements

List1: List of values

Output

Print "True" if list is strictly increasing or decreasing else print "False"

Sample Test Case

Input

1
2

5
6

Output

True

Answer: (penalty regime: 0 %)


1 n=int(input())
2 l=[]
3 ▼ for x in range(n):
4 [Link](int(input()))
5 flag1=0
6 flag2=0
7 ▼ for i in range(1,n):
8 ▼ if not(l[i]<l[i-1]):
9 flag1+=1
10 ▼ if flag1<=1 or flag2<=0:
11 print(True)

Input Expected Got

7 True True
1
2
3
0
4
5
6

92
Input Expected Got

4 True True
2
1
0
-1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

93
Question 8
Correct

Mark 1.00 out of 1.00

Output is a merged array without duplicates.


Input Format
N1 - no of elements in array 1

Array elements for array 1

N2 - no of elements in array 2

Array elements for array2

Output Format

Display the merged array


Sample Input 1
5

1
2

3
6

9
4

2
4
5

10
Sample Output 1

1 2 3 4 5 6 9 10

Answer: (penalty regime: 0 %)


1 n1=int(input())
2 l1=[]
3 ▼ for x in range(n1):
4 [Link](int(input()))
5 n2=int(input())
6 l2=[]
7 ▼ for y in range(n2):
8 [Link](int(input()))
9 ▼ for i in l1:
10 ▼ if i in l2:
11 [Link](i)
12 ▼ else:
13 pass
14 [Link](l2)
15 [Link]()
16 ▼ for j in l1:
17 print(j, end=" ")

94
Input Expected Got

5 1 2 3 4 5 6 9 10 1 2 3 4 5 6 9 10
1
2
3
6
9
4
2
4
5
10

7 1 3 4 5 7 8 10 11 12 13 22 30 35 1 3 4 5 7 8 10 11 12 13 22 30 35
4
7
8
10
12
30
35
9
1
3
4
5
7
8
11
13
22

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

95
Question 9
Correct

Mark 1.00 out of 1.00

Determine the factors of a number (i.e., all positive integer values that evenly divide into a number) and then return the pth element of the
list, sorted ascending. If there is no pth element, return 0.

Example

n = 20

p=3
The factors of 20 in ascending order are {1, 2, 4, 5, 10, 20}. Using 1-based indexing, if p = 3, then 4 is returned. If p > 6, 0 would be
returned.

Constraints

1 ≤ n ≤ 1015

1 ≤ p ≤ 109
The first line contains an integer n, the number to factor.

The second line contains an integer p, the 1-based index of the factor to return.

Sample Case 0

Sample Input 0

10

Sample Output 0

Explanation 0

Factoring n = 10 results in {1, 2, 5, 10}. Return the p = 3rd factor, 5, as the answer.

Sample Case 1
Sample Input 1

10

Sample Output 1

Explanation 1

Factoring n = 10 results in {1, 2, 5, 10}. There are only 4 factors and p = 5, therefore 0 is returned as the answer.

Sample Case 2

Sample Input 2
1

Sample Output 2

Explanation 2

Factoring n = 1 results in {1}. The p = 1st factor of 1 is returned as the answer.

For example:

Input Result

10 5
3

10 0
5

96
Input Result

1 1
1

Answer: (penalty regime: 0 %)


1 n=int(input())
2 factors=[]
3 ▼ for i in range(1,n+1):
4 ▼ if n%i==0:
5 [Link](i)
6 p=int(input())
7 ▼ if (p<=len(factors)):
8 print(factors[p-1])
9 ▼ else:
10 print(0)

Input Expected Got

10 5 5
3

10 0 0
5

1 1 1
1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

97
Question 10
Correct

Mark 1.00 out of 1.00

Given an array A of sorted integers and another non negative integer k, find if there exists 2 indices i and j such that A[i] - A[j] = k, i != j.
Input Format

1. First line is number of test cases T. Following T lines contain:

2. N, followed by N integers of the array

3. The non-negative integer k


Output format

Print 1 if such a pair exists and 0 if it doesn’t.

Example

Input

1
3

4
Output:

Input

1
3

5
99

Output

For example:

Input Result

1 1
3
1
3
5
4

1 0
3
1
3
5
99

Answer: (penalty regime: 0 %)


1 T=int(input())
2 ▼ for x in range(T):
3 N=int(input())
4 A=[]
5 ▼ for y in range(N):
6 [Link](int(input()))
98
7 k=int(input())
8 found=0
9 ▼ for i in range(N):
10 ▼ for j in range(N):
11 difference=abs(A[j]-A[i])
12 ▼ if i!=j and difference==k:
13 found=1
14 break
15 ▼ else:
16 pass
17 print(found)

Input Expected Got

1 1 1
3
1
3
5
4

1 0 0
3
1
3
5
99

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week 7_MCQ

Jump to...

Tuples ►

99
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Experiments based on Tuples, Sets and its operations / Week 8_Coding

Status Finished
Started Wednesday, 7 May 2025, 7:17 PM
Completed Wednesday, 14 May 2025, 9:46 PM
Duration 7 days 2 hours
Marks 5.00/5.00
Grade 100.00 out of 100.00

100
Question 1
Correct

Mark 1.00 out of 1.00

Write a program to eliminate the common elements in the given 2 arrays and print only the non-repeating
elements and the total number of such non-repeating elements.

Input Format:

The first line contains space-separated values, denoting the size of the two arrays in integer format respectively.
The next two lines contain the space-separated integer arrays to be compared.
Sample Input:

54

12865

2 6 8 10

Sample Output:
1 5 10

Sample Input:

55

12345
12345

Sample Output:

NO SUCH ELEMENTS

For example:

Input Result

5 4 1 5 10
1 2 8 6 5 3
2 6 8 10

Answer: (penalty regime: 0 %)


1 x=input()
2 y=input().split()
3 z=input().split()
4 l1=[]
5 l2=[]
6 ▼ for i in y:
7 [Link](int(i))
8 ▼ for j in z:
9 [Link](int(j))
10 a=set(l1)
11 b=set(l2)
12 c=a^b
13 l3=list(c)
14 ▼ if(l3==[]):
15 print("NO SUCH ELEMENTS")
16 ▼ else:
17 ▼ for k in l3:
18 print(k, end=" ")
19 print()
20 print(len(l3))

101
Input Expected Got

5 4 1 5 10 1 5 10
1 2 8 6 5 3 3
2 6 8 10

3 3 11 12 11 12
10 10 10 2 2
10 11 12

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

102
Question 2
Correct

Mark 1.00 out of 1.00

Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the
image below.

In the American keyboard:

the first row consists of the characters "qwertyuiop",


the second row consists of the characters "asdfghjkl", and
the third row consists of the characters "zxcvbnm".

Example 1:
Input: words = ["Hello","Alaska","Dad","Peace"]
Output: ["Alaska","Dad"]

Example 2:
Input: words = ["omk"]
Output: []

Example 3:
Input: words = ["adsdf","sfd"]
Output: ["adsdf","sfd"]

For example:

Input Result

4 Alaska
Hello Dad
Alaska
Dad
Peace

2 adsfd
adsfd afd
afd

Answer: (penalty regime: 0 %)


1 n=int(input())
2 l=[]
3 ▼ for x in range(n):
4 [Link](input())
5 s1=set("qwertyuiop")
6 s2=set("asdfghjkl")
7 s3=set("zxcvbnm")
8 m=[]
9 ▼ for i in l:
10 x=set([Link]())
11 ▼ if(x<=s1):
12 [Link](i)
103
13 ▼ elif(x<=s2):
14 [Link](i)
15 ▼ elif(x<=s3):
16 [Link](i)
17 ▼ if (m==[]):
print("No words")
▼ else:
▼ for j in m:
print(j)

Input Expected Got

4 Alaska Alaska
Hello Dad Dad
Alaska
Dad
Peace

1 No words No words
omk

2 adsfd adsfd
adsfd afd afd
afd

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

104
Question 3
Correct

Mark 1.00 out of 1.00

Coders here is a simple task for you, Given string str. Your task is to check whether it is a binary string or not by using python set.
Examples:

Input: str = "01010101010"

Output: Yes

Input: str = "REC101"


Output: No

For example:

Input Result

01010101010 Yes

010101 10101 No

Answer: (penalty regime: 0 %)


1 a=input()
2 s1=set(a)
3 s2={'0','1'}
4 ▼ if s2==s1:
5 print("Yes")
6 ▼ else:
7 print("No")

Input Expected Got

01010101010 Yes Yes

REC123 No No

010101 10101 No No

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

105
Question 4
Correct

Mark 1.00 out of 1.00

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] [Link] is only one repeated
number in nums, return this repeated number. Solve the problem using set.

Example 1:
Input: nums = [1,3,4,2,2]

Output: 2

Example 2:
Input: nums = [3,1,3,4,2]

Output: 3

For example:

Input Result

1 3 4 4 2 4

Answer: (penalty regime: 0 %)


1 a=input()
2 s=set()
3 ▼ for i in a:
4 ▼ if i not in s:
5 pass
6 ▼ else:
7 print(i)
8 [Link](i)

Input Expected Got

1 3 4 4 2 4

1 2 2 3 4 5 6 7 2
2

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

106
Question 5
Correct

Mark 1.00 out of 1.00

The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.

For example, "ACGAATTCCG" is a DNA sequence.

When studying DNA, it is useful to identify repeated sequences within the DNA.

Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA
molecule. You may return the answer in any order.

Example 1:
Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
Output: ["AAAAACCCCC","CCCCCAAAAA"]

Example 2:
Input: s = "AAAAAAAAAAAAA"
Output: ["AAAAAAAAAA"]

For example:

Input Result

AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT AAAAACCCCC
CCCCCAAAAA

Answer: (penalty regime: 0 %)


1 s=input()
2 l=[]
3 r=set()
4 ▼ for i in range(len(s)-9):
5 t=s[i:i+10]
6 ▼ if t in l:
7 [Link](t)
8 ▼ else:
9 [Link](t)
10 a=list(r)
11 ▼ for j in a:
12 print(j)

Input Expected Got

AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT AAAAACCCCC AAAAACCCCC


CCCCCAAAAA CCCCCAAAAA

AAAAAAAAAAAAA AAAAAAAAAA AAAAAAAAAA

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week 8_MCQ

Jump to...

Dictionary ►
107
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Experiments based on Dictionary and its operations. / Week 9_Coding

Status Finished
Started Saturday, 24 May 2025, 6:58 AM
Completed Wednesday, 28 May 2025, 7:35 PM
Duration 4 days 12 hours
Marks 5.00/5.00
Grade 100.00 out of 100.00

108
Question 1

Correct

Mark 1.00 out of 1.00

Give a dictionary with value lists, sort the keys by summation of values in value list.
Input : test_dict = {‘Gfg’ : [6, 7, 4], ‘best’ : [7, 6, 5]}

Output : {‘Gfg’: 17, ‘best’: 18}


Explanation : Sorted by sum, and replaced.
Input : test_dict = {‘Gfg’ : [8,8], ‘best’ : [5,5]}
Output : {‘best’: 10, ‘Gfg’: 16}
Explanation : Sorted by sum, and replaced.
Sample Input:
2
Gfg 6 7 4
Best 7 6 5
Sample Output
Gfg 17
Best 18

For example:

Input Result

2 Gfg 17
Gfg 6 7 4 Best 18
Best 7 6 5

Answer: (penalty regime: 0 %)


1 n=int(input())
2 d={}
3 ▼ for i in range(n):
4 b=input().split()
5 c=b[0]
6 [Link](b[0])
7 l=[]
8 ▼ for j in b:
9 [Link](int(j))
10 a=sum(l)
11 d[c]=a
12 d1=sorted([Link]())
13 ▼ for i in d1:
14 ▼ for j in d:
15 ▼ if i==d[j]:
16 print(j,i)

Input Expected Got

2 Gfg 17 Gfg 17
Gfg 6 7 4 Best 18 Best 18
Best 7 6 5

109
Input Expected Got

2 Best 10 Best 10
Gfg 6 6 Gfg 12 Gfg 12
Best 5 5

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

110
Question 2

Correct

Mark 1.00 out of 1.00

Given an array of names of candidates in an election. A candidate name in the array represents a vote cast to the candidate. Print the name of
candidates received Max vote. If there is tie, print a lexicographically smaller name.
Examples:
Input : votes[] = {"john", "johnny", "jackie",
"johnny", "john", "jackie",
"jamie", "jamie", "john",
"johnny", "jamie", "johnny",
"john"};
Output : John
We have four Candidates with name as 'John', 'Johnny', 'jamie', 'jackie'. The candidates John and Johny get maximum votes. Since John is
alphabetically smaller, we print it. Use dictionary to solve the above problem

Sample Input:
10
John
John
Johny
Jamie
Jamie
Johny
Jack
Johny
Johny
Jackie

Sample Output:
Johny

Answer: (penalty regime: 0 %)


1 n=int(input())
2 d={}
3 ▼ for i in range(n):
4 a=input()
5 ▼ if a in d:
6 d[a]+=1
7 ▼ else:
8 d[a]=1
9 top=max([Link]())
10 winner=[]
111
11 ▼ for i in d:
12 ▼ if d[i]==top:
13 [Link](i)
14 print(min(winner))

Input Expected Got

10 Johny Johny
John
John
Johny
Jamie
Jamie
Johny
Jack
Johny
Johny
Jackie

6 Ida Ida
Ida
Ida
Ida
Kiruba
Kiruba
Kiruba

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

112
Question 3

Correct

Mark 1.00 out of 1.00

In the game of Scrabble™, each letter has points associated with it. The total score of a word is the sum of the scores of its letters. More
common letters are worth fewer points while less common letters are worth more points. The points associated with each letter are shown
below:
Points Letters
1 A, E, I, L, N, O, R, S, T and U
2 D and G
3 B, C, M and P
4 F, H, V, W and Y
5K
8 J and X
10 Q and Z
Write a program that computes and displays the Scrabble™ score for a word. Create a dictionary that maps from letters to point values. Then
use the dictionary to compute the score.
A Scrabble™ board includes some squares that multiply the value of a letter or the value of an entire word. We will ignore these squares in this
exercise.
Sample Input
REC
Sample Output
REC is worth 5 points.

For example:

Input Result

REC REC is worth 5 points.

Answer: (penalty regime: 0 %)


1 a=input().upper()
2 d={"A":1, "E":1, "I":1, "L":1, "N":1, "O":1, "R":1, "S":1, "T":1, "U":1,
3 "D":2, "G":2,
4 "B":3, "C":3, "M":3, "P":3,
5 "F":4, "H":4, "V":4, "W":4, "Y":4,
6 "K":5,
7 "J":8, "X":8,
8 "Q":10, "Z":10}
9 l=[]
10 ▼ for i in a:
11 [Link](i)
12 points=0
13 ▼ for i in l:
14 points+=d[i]
15 print(a, "is worth", points, "points.")

Input Expected Got

GOD GOD is worth 5 points. GOD is worth 5 points.

REC REC is worth 5 points. REC is worth 5 points.


Passed all tests!

Correct
Marks for this submission: 1.00/1.00.
113
Question 4

Correct

Mark 1.00 out of 1.00

A sentence is a string of single-space separated words where each word consists only of lowercase letters.A word is uncommon if it appears
exactly once in one of the sentences, and does not appear in the other sentence.
Given two sentences s1 and s2, return a list of all the uncommon words. You may return the answer in any order.
Example 1:
Input: s1 = "this apple is sweet", s2 = "this apple is sour"
Output: ["sweet","sour"]
Example 2:
Input: s1 = "apple apple", s2 = "banana"
Output: ["banana"]
Constraints:

1 <= [Link], [Link] <= 200


s1 and s2 consist of lowercase English letters and spaces.
s1 and s2 do not have leading or trailing spaces.
All the words in s1 and s2 are separated by a single space.
Note:
Use dictionary to solve the problem

For example:

Input Result

this apple is sweet sweet sour


this apple is sour

Answer: (penalty regime: 0 %)


1 a=input().split()
2 b=input().split()
3 c=a+b
4 d={}
5 ▼ for i in c:
6 ▼ if i in d:
7 d[i]+=1
8 ▼ else:
9 d[i]=1
10 m=min([Link]())
11 l=[]
12 ▼ for i in d:
13 ▼ if d[i]==m:
14 [Link](i)
15 print(" ".join(l))

Input Expected Got

this apple is sweet sweet sour sweet sour


this apple is sour

apple apple banana banana


banana

Passed all tests!

Correct
114
Marks for this submission: 1.00/1.00.
Question 5

Correct

Mark 1.00 out of 1.00

Create a student dictionary for n students with the student name as key and their test mark assignment mark and lab mark as values. Do the
following computations and display the result.
1. Identify the student with the highest average score

2. Identify the student who as the highest Assignment marks

3. Identify the student with the Lowest lab marks

4. Identify the student with the lowest average score

Note:
If more than one student has the same score display all the student names

Sample input:
4
James 67 89 56
Lalith 89 45 45
Ram 89 89 89
Sita 70 70 70
Sample Output:
Ram
James Ram
Lalith
Lalith

For example:

Input Result

4 Ram
James 67 89 56 James Ram
Lalith 89 45 45 Lalith
Ram 89 89 89 Lalith
Sita 70 70 70

Answer: (penalty regime: 0 %)


1 n=int(input())
2 d={}
3 ▼ for i in range(n):
4 name,test,assign,lab=input().split()
5 test=int(test)
6 assign=int(assign)
7 lab=int(lab)
8 d[name]=(test,assign,lab)
9 l1=[]
10 ▼ for marks in [Link]():
11 [Link](sum(marks)/3)
12 a=max(l1)
13 HA=[]
14 ▼ for name,marks in [Link]():
15 ▼ if (sum(marks)/3==a):
16 [Link](name)
17 [Link]()
18 l2=[]
19 ▼ for marks in [Link]():
20 [Link](marks[1])
115
21 b=max(l2)
22 AM=[]
23 ▼ for name,marks in [Link]():
24 ▼ if (marks[1]==b):
25 [Link](name)
26 [Link]()
27 l3=[]
28 ▼ for marks in [Link]():
29 [Link](marks[2])
30 c=min(l3)
31 LM=[]
32 ▼ for name,marks in [Link]():
33 ▼ if (marks[2]==c):
34 [Link](name)
35 [Link]()
36 l4=[]
37 ▼ for marks in [Link]():
38 [Link](sum(marks)/3)
39 e=min(l4)
40 LA=[]
41 ▼ for name,marks in [Link]():
42 ▼ if (sum(marks)/3==e):
43 [Link](name)
44 [Link]()
45 ▼ for i in HA:
46 print(i,end=" ")
47 print()
48 ▼ for i in AM:
49 print(i,end=" ")
50 print()
51 ▼ for i in LM:
52 print(i,end=" ")

Input Expected Got

4 Ram Ram
James 67 89 56 James Ram James Ram
Lalith 89 45 45 Lalith Lalith
Ram 89 89 89 Lalith Lalith
Sita 70 70 70

3 Shadhana Shadhana
Raja 95 67 90 Shadhana Shadhana
Aarav 89 90 90 Aarav Raja Aarav Raja
Shadhana 95 95 91 Raja Raja

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week 9_MCQ

Jump to...

Searching ►

116
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Searching techniques: Linear and Binary / Week10_Coding

Status Finished
Started Wednesday, 28 May 2025, 7:36 PM
Completed Wednesday, 28 May 2025, 9:50 PM
Duration 2 hours 13 mins
Marks 5.00/5.00
Grade 100.00 out of 100.00

117
Question 1
Correct

Mark 1.00 out of 1.00

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. You read
an list of numbers. You need to arrange the elements in ascending order and print the result. The sorting should be done using bubble sort.

Input Format: The first line reads the number of elements in the array. The second line reads the array elements one by one.

Output Format: The output should be a sorted list.

For example:

Input Result

6 1 2 3 4 7 8
3 4 8 7 1 2

5 1 2 3 4 5
4 5 2 3 1

Answer: (penalty regime: 0 %)


1 n=int(input())
2 a=input().split()
3 l=[]
4 ▼ for i in a:
5 [Link](int(i))
6 ▼ for i in range(n-1):
7 ▼ for j in range(n-i-1):
8 ▼ if l[j]>l[j+1]:
9 l[j],l[j+1]=l[j+1],l[j]
10 ▼ for i in l:
11 print(i, end=" ")

Input Expected Got

6 1 2 3 4 7 8 1 2 3 4 7 8
3 4 8 7 1 2

6 1 3 4 6 9 18 1 3 4 6 9 18
9 18 1 3 4 6

5 1 2 3 4 5 1 2 3 4 5
4 5 2 3 1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

118
Question 2
Correct

Mark 1.00 out of 1.00

Given an listof integers, sort the array in ascending order using the Bubble Sort algorithm above. Once sorted, print the following three lines:
1. List is sorted in numSwaps swaps., where numSwaps is the number of swaps that took place.

2. First Element: firstElement, the first element in the sorted list.

3. Last Element: lastElement, the last element in the sorted list.

For example, given a worst-case but small array to sort: a=[6,4,1]. It took 3 swaps to sort the array. Output would be
Array is sorted in 3 swaps.

First Element: 1

Last Element: 6

Input Format

The first line contains an integer,n , the size of the list a .


The second line contains n, space-separated integers a[i].
Constraints

· 2<=n<=600

· 1<=a[i]<=2x106.

Output Format
You must print the following three lines of output:

1. List is sorted in numSwaps swaps., where numSwaps is the number of swaps that took place.

2. First Element: firstElement, the first element in the sorted list.

3. Last Element: lastElement, the last element in the sorted list.

Sample Input 0
3

123

Sample Output 0

List is sorted in 0 swaps.


First Element: 1
Last Element: 3

For example:

Input Result

3 List is sorted in 3 swaps.


3 2 1 First Element: 1
Last Element: 3

5 List is sorted in 4 swaps.


1 9 2 8 4 First Element: 1
Last Element: 9

Answer: (penalty regime: 0 %)


1 n=int(input())
2 a=input().split()
3 l=[]
4 ▼ for i in a:
5 [Link](int(i))
6 swaps=0
7 ▼ for i in range(n-1):
8 ▼ for j in range(n-i-1):
9 ▼ if l[j]>l[j+1]:
10 l[j],l[j+1]=l[j+1],l[j]
11 swaps+=1 119
print("List is sorted in", swaps, "swaps.")
print("First Element:", l[0])
print("Last Element:", l[-1])

Input Expected Got

3 List is sorted in 3 swaps. List is sorted in 3 swaps.


3 2 1 First Element: 1 First Element: 1
Last Element: 3 Last Element: 3

5 List is sorted in 4 swaps. List is sorted in 4 swaps.


1 9 2 8 4 First Element: 1 First Element: 1
Last Element: 9 Last Element: 9

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

120
Question 3
Correct

Mark 1.00 out of 1.00

Write a Python program for binary search.

For example:

Input Result

1,2,3,5,8 False
6

3,5,9,45,42 True
42

Answer: (penalty regime: 0 %)


1 a=input().split(",")
2 l1=[]
3 ▼ for i in a:
4 [Link](int(i))
5 b=int(input())
6 flag=False
7 ▼ for i in range(len(l1)):
8 ▼ if l1[i]==b:
9 flag=True
10 ▼ else:
11 flag=False
12 print(flag)

Input Expected Got

1,2,3,5,8 False False


6

3,5,9,45,42 True True


42

52,45,89,43,11 True True


11

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

121
[Link]/moodle/mod/quiz/[Link]?attempt=218302&cmid=604 5/8
Week10_Coding: Attempt review | REC-CIS

Question 4

Correct

Mark 1.00 out of 1.00

Write a Python program to sort a list of elements using the merge sort algorithm.

For example:

Input Result

5 3 4 5 6 8
6 5 4 3 8

Answer: (penalty regime: 0 %)


1 n=int(input())
2 a=input().split()
3 l=[]
4 ▼ for i in a:
5 [Link](int(i))
6 [Link]()
7 ▼ for i in l:
8 print(i, end=" ")

Input Expected Got

5 3 4 5 6 8 3 4 5 6 8
6 5 4 3 8

9 14 21 27 41 43 45 46 57 70 14 21 27 41 43 45 46 57 70
14 46 43 27 57 41 45 21 70

4 23 43 49 86 23 43 49 86
86 43 23 49

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

122
[Link]/moodle/mod/quiz/[Link]?attempt=218302&cmid=604 6/8
Question 5
Correct

Mark 1.00 out of 1.00

To find the frequency of numbers in a list and display in sorted order.


Constraints:

1<=n, arr[i]<=100

Input:

1 68 79 4 90 68 1 4 5
output:

12

42

51

68 2
79 1

90 1

For example:

Input Result

4 3 5 3 4 5 3 2
4 2
5 2

Answer: (penalty regime: 0 %)


1 a=input().split()
2 l=[]
3 ▼ for i in a:
4 [Link](int(i))
5 s=set(l)
6 L=list(s)
7 [Link]()
8 ▼ for i in L:
9 print(i, [Link](i))

Input Expected Got

4 3 5 3 4 5 3 2 3 2
4 2 4 2
5 2 5 2

12 4 4 4 2 3 5 2 1 2 1
3 1 3 1
4 3 4 3
5 1 5 1
12 1 12 1

123
Input Expected Got

5 4 5 4 6 5 7 3 3 1 3 1
4 2 4 2
5 3 5 3
6 1 6 1
7 1 7 1

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week10_MCQ

Jump to...

Sorting ►

124
Dashboard / My courses / GE23231/GE23233-PUP/PSPP-2024 / Sorting techniques: Bubble and Merge Sort. / Week 11_Coding

Status Finished
Started Wednesday, 28 May 2025, 7:36 PM
Completed Wednesday, 28 May 2025, 11:18 PM
Duration 3 hours 41 mins
Marks 2.00/2.00
Grade 40.00 out of 40.00 (100%)

Question 1
Correct

Mark 1.00 out of 1.00

Write a program that implements the Bubble Sort algorithm to sort an array of integers in ascending order.

In Bubble Sort, each pair of adjacent elements is compared, and the elements are swapped if they are in the wrong order. This process is
repeated until the array is sorted.

Input Format:
The first line contains a single integer n — the number of elements in the array.

The second line contains n space-separated integers — the elements of the array.

Output Format:
Output a single line containing the sorted array, with elements separated by spaces.

Answer: (penalty regime: 0 %)


n=int(input())
a=input().split()
l=[]
▼ for i in a:
[Link](int(i))
▼ for i in range(n-1):
▼ for j in range(n-i-1):
▼ if l[j]>l[j+1]:
9 l[j],l[j+1]=l[j+1],l[j]
▼ for i in l:
print(i, end=" ")

Input Expected Got

5 1 2 4 5 8 1 2 4 5 8
5 1 4 2 8

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

125
Question 2
Correct

Mark 1.00 out of 1.00

Write a program that implements the Merge Sort algorithm to sort an array of integers in ascending order.

Merge Sort is a divide and conquer algorithm that divides the array into halves, recursively sorts them, and then merges the sorted halves
to produce the sorted array.

Input Format:
The first line contains a single integer n — the number of elements in the array.

The second line contains n space-separated integers — the elements of the array.

Output Format:
Output a single line containing the sorted array in ascending order, with elements separated by spaces.

Constraints:
1 <= n <= 10^5

-10^9 <= arr[i] <= 10^9 for each element in the array

Answer: (penalty regime: 0 %)


n=int(input())
a=input().split()
l=[]
▼ for i in a:
[Link](int(i))
[Link]()
▼ for i in l:
print(i, end=" ")

Input Expected Got

5 3 9 27 38 43 3 9 27 38 43
38 27 43 3 9

6 5 6 7 11 12 13 5 6 7 11 12 13
12 11 13 5 6 7

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Week 11_MCQ

Jump to...

126

You might also like