Programming Using Python Lab Record - 240401012-1
Programming Using Python Lab Record - 240401012-1
Akshaya Sri . S
2116240401006
II
2024-2025
1
List of Experiments
2
CO-PO-PSO Mapping
3
INDEX
2116240401012 Barathkumar. S
[Link]
I Biotechnology FA
Page Teacher’s
S. No. Date Title No. Signature
Operators in Python
2.1 12/03/25 Rotaract Club 18
4
3.5 23/03/25 Vowel or Consonant 38
5
6.6 03/05/25 Palindrome 75
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
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
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'>
Correct
9
Marks for this submission: 1.00/1.00.
Question 2
Correct
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
Correct
Marks for this submission: 1.00/1.00.
10
Question 3
Correct
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
Correct
Marks for this submission: 1.00/1.00.
11
Question 4
Correct
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
Sample Input:
10000
250
15000
Sample Output:
For example:
Input Result
12
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
13
Question 5
Correct
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
For example:
Input Result
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
Correct
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
15
Input Expected Got
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
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:
Sample Input
19
45
Sample Output
True
For example:
Input Result
18 False
40
18
Input Expected Got
19 True True
45
18 False False
40
18 True True
42
16 False False
45
Correct
Marks for this submission: 1.00/1.00.
19
Question 2
Correct
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
Correct
Marks for this submission: 1.00/1.00.
20
Question 3
Correct
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
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
For example:
Input Result
21
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
22
Question 4
Correct
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
3 2 2
5 2 2
15 4 4
Correct
Marks for this submission: 1.00/1.00.
23
Question 5
Correct
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.
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
56 True True
-1 False False
Correct
Marks for this submission: 1.00/1.00.
24
Question 6
Correct
[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:
Input Format:
An integer x, 0<=x<=1. .
Output Format:
Input 2:
1
Output 1:
D
For example:
Input Result
0 C
25
Input Expected Got
0 C C
1 D D
Correct
Marks for this submission: 1.00/1.00.
26
Question 7
Correct
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.
For example:
Input Result
197 7
-197 7
197 7 7
-197 7 7
Correct
Marks for this submission: 1.00/1.00.
27
Question 8
Correct
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:
Output Format:
32
43
Sample Output:'
False
For example:
Input Result
32 False
43
32 False False
43
28
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
Question 9
Correct
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.
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.
Correct
Marks for this submission: 10.00/10.00.
29
Question 10
Correct
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
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
Correct
Marks for this submission: 1.00/1.00.
◄ Week2_MCQ
Jump to...
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
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
197 9 9
-197 9 9
5 -1 -1
123456 5 5
8 -1 -1
Correct
Marks for this submission: 1.00/1.00.
32
Question 2
Correct
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:
• Of the remaining years, any year that is divisible by 100 is not a leap year.
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
Correct
Marks for this submission: 1.00/1.00.
33
Question 3
Correct
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
Sample Input 2
40
40
80
Sample Output 2
50
60
70
Sample Output 3
That's a scalene triangle
For example:
Input Result
34
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
35
Question 4
Correct
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
Sample Input 2
2020
Sample Output 2
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.
Correct
Marks for this submission: 1.00/1.00.
37
Question 5
Correct
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
Sample Input3
Sample Output 3
It's a consonant.
For example:
Input Result
c It's a consonant.
y Sometimes it's a vowel... Sometimes it's a Sometimes it's a vowel... Sometimes it's a
consonant. consonant.
38
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
39
Question 6
Correct
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:
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
50 100.00 100.00
40
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
41
Question 7
Correct
Write a program to find the eligibility of admission for a professional course based on the following criteria:
Marks in Maths >= 65
Or
Test Case 1
Input
70
60
80
Output
Test Case 2
Input
50
80
80
Output
The candidate is eligible
Test Case 3
Input
50
60
40
Output
For example:
Input Result
42
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
43
Question 8
Correct
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
Test Case 1
Input
3
5
Output
yes
Test Case 2
Input
5
8
2
Output
no
44
Input Expected Got
3 yes yes
5
4
5 no no
8
2
Correct
Marks for this submission: 1.00/1.00.
45
Question 9
Correct
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:
The first integer corresponds to the number of problems given and the second integer corresponds to the number of problems solved.
Output Format:
Input
Output
OUT
For example:
Input Result
8 OUT
3
46
Input Expected Got
8 OUT OUT
3
8 IN IN
5
20 OUT OUT
9
50 IN IN
31
Correct
Marks for this submission: 1.00/1.00.
47
Question 10
Correct
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
For example:
Input Result
48
Passed all tests!
Correct
Marks for this submission: 1.00/1.00.
◄ Week3_MCQ
Jump to...
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
Given a positive integer N, check whether it can be represented as a product of single digit numbers.
Input Format:
Output Format:
Output:
Yes
Example Input:
13
Output:
No
14 Yes Yes
13 No No
Correct
Marks for this submission: 1.00/1.00.
51
Question 2
Correct
i.e. Fibonacci series starts with 0 and 1, and continues generating the next number as the sum of the previous two numbers.
For example:
Input Result
1 0
4 2
7 8
1 0 0
4 2 2
7 8 8
Correct
Correct
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
292 1 1
1015 2 2
108 3 3
22 0 0
Correct
Marks for this submission: 1.00/1.00.
53
Question 4
Correct
Given an integer N, check whether N the given number can be made a perfect square after adding to it.
Input Format:
Output Format:
Yes or No.
Example Input:
24
Output:
Yes
Example Input:
26
Output:
No
For example:
Input Result
24 Yes
24 Yes Yes
26 No No
Correct
Marks for this submission: 1.00/1.00.
54
Question 5
Correct
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.
For example:
Input Result
7 2
10 1
7 2 2
10 1 1
Correct
Marks for this submission: 1.00/1.00.
55
Question 6
Correct
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:
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
123 No No
Correct
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
292 2 2
1015 3 3
123 3 3
Correct
Marks for this submission: 1.00/1.00.
57
Question 8
Correct
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
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.
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
5 120 120
4 24 24
9 362880 362880
Correct
Marks for this submission: 1.00/1.00.
58
Question 9
Correct
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)
Input
Output
1234
Test Case 2
Input
6
Output
123456
4 1234 1234
6 123456 123456
Correct
Marks for this submission: 1.00/1.00.
59
Question 10
Correct
Output Format:
10
Output:
16
10 16 16
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
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
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
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")
Correct
Marks for this submission: 1.00/1.00.
62
Question 2
Correct
complete function to implement coin change making problem i.e. finding the minimum
Output Format:
return the minimum number of coins required to meet the given target.
Example Input:
16
Output:
Explanation:
25
Output:
Explanation:
We need 6 coins of 4 value, and 1 coin of 1 value
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
print(coinChange(16)) 4 4
Correct
Marks for this submission: 1.00/1.00.
63
Question 3
Correct
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:
12
Output:
Yes
Explanation
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
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(13)) No No
Correct
Marks for this submission: 1.00/1.00.
65
Question 4
Correct
Given a number with maximum of 100 digits as input, find the difference between the sum
Input Format:
Take a number in the form of String from stdin.
Output Format:
Example input:
1453
Output:
Explanation:
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)
print(differenceSum(1453)) 1 1
Correct
Marks for this submission: 1.00/1.00.
66
Question 5
Correct
Write a code to check whether product of digits at even places is divisible by sum of digits
Input Format:
Take an input integer from stdin.
Output Format:
Example Input:
1256
Output:
TRUE
Example Input:
1595
Output:
FALSE
For example:
Test Result
print(productDigits(1256)) True
print(productDigits(1595)) False
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"
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
Write a program that takes as input a string (sentence), and returns its second word in uppercase.
For example:
NOTE 1: If input is a sentence with less than 2 words, the program should return the word “LESS”.
For example:
Input Result
Hello LESS
Correct
Marks for this submission: 1.00/1.00.
70
Question 2
Correct
For example:
Input Result
A&x# x&A#
Correct
Marks for this submission: 1.00/1.00.
71
Question 3
Correct
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
first
second
third
Correct
Marks for this submission: 1.00/1.00.
72
Question 4
Correct
Given two Strings s1 and s2, remove all the characters from s1 which is present in s2.
Constraints
Sample Input 1
experience
enc
Sample Output 1
xpri
Correct
Marks for this submission: 1.00/1.00.
73
Question 5
Correct
Sample Input 1
a2b4c6
Sample Output 1
aabbbbcccccc
Correct
Marks for this submission: 1.00/1.00.
74
Question 6
Correct
Sample Input 1
Sample Output 1
is my mother tongue
Correct
Marks for this submission: 1.00/1.00.
75
Question 7
Correct
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
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
Correct
Marks for this submission: 1.00/1.00.
76
Question 8
Correct
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:
Boundary Condition:
1 <= Length of S <= 100
Example Input/Output 1:
Input:
abcd@[Link]
Output:
com
gmail
abcd
Correct
Marks for this submission: 1.00/1.00.
77
Question 9
Correct
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
Yn True True
PYnative
Correct
Marks for this submission: 1.00/1.00.
78
Question 10
Correct
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:
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:
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
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.
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
Correct
Marks for this submission: 1.00/1.00.
82
Question 2
Correct
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.
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
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
Correct
Marks for this submission: 1.00/1.00.
84
Question 3
Correct
Complete the program to count frequency of each element of an array. Frequency of a particular element will be printed once.
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
Correct
Marks for this submission: 1.00/1.00.
85
Question 4
Correct
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.
Constraints
· 3 ≤ n ≤ 105
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
· 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
4 2 2
1
2
3
3
3 1 1
1
2
1
Correct
Marks for this submission: 1.00/1.00.
87
Question 5
Correct
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.
5
6
5
7
5 is present at location 1
5 is present at location 3
5 is present 2 times in the array.
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
Correct
Marks for this submission: 1.00/1.00.
89
Question 6
Correct
Input:
m : row size
n: column size
Output
Sample input
2
2
1
7
2
8
Sample Output
90
Input Expected Got
Correct
Marks for this submission: 1.00/1.00.
91
Question 7
Correct
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
Output
Input
1
2
5
6
Output
True
7 True True
1
2
3
0
4
5
6
92
Input Expected Got
4 True True
2
1
0
-1
Correct
Marks for this submission: 1.00/1.00.
93
Question 8
Correct
N2 - no of elements in array 2
Output Format
1
2
3
6
9
4
2
4
5
10
Sample Output 1
1 2 3 4 5 6 9 10
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
Correct
Marks for this submission: 1.00/1.00.
95
Question 9
Correct
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
For example:
Input Result
10 5
3
10 0
5
96
Input Result
1 1
1
10 5 5
3
10 0 0
5
1 1 1
1
Correct
Marks for this submission: 1.00/1.00.
97
Question 10
Correct
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
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
1 1 1
3
1
3
5
4
1 0 0
3
1
3
5
99
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
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
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
Correct
Marks for this submission: 1.00/1.00.
102
Question 2
Correct
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.
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
4 Alaska Alaska
Hello Dad Dad
Alaska
Dad
Peace
1 No words No words
omk
2 adsfd adsfd
adsfd afd afd
afd
Correct
Marks for this submission: 1.00/1.00.
104
Question 3
Correct
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:
Output: Yes
For example:
Input Result
01010101010 Yes
010101 10101 No
REC123 No No
010101 10101 No No
Correct
Marks for this submission: 1.00/1.00.
105
Question 4
Correct
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
1 3 4 4 2 4
1 2 2 3 4 5 6 7 2
2
Correct
Marks for this submission: 1.00/1.00.
106
Question 5
Correct
The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.
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
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
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]}
For example:
Input Result
2 Gfg 17
Gfg 6 7 4 Best 18
Best 7 6 5
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
Correct
Marks for this submission: 1.00/1.00.
110
Question 2
Correct
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
10 Johny Johny
John
John
Johny
Jamie
Jamie
Johny
Jack
Johny
Johny
Jackie
6 Ida Ida
Ida
Ida
Ida
Kiruba
Kiruba
Kiruba
Correct
Marks for this submission: 1.00/1.00.
112
Question 3
Correct
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
Correct
Marks for this submission: 1.00/1.00.
113
Question 4
Correct
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:
For example:
Input Result
Correct
114
Marks for this submission: 1.00/1.00.
Question 5
Correct
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
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
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
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
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.
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
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
Correct
Marks for this submission: 1.00/1.00.
118
Question 2
Correct
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.
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
· 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.
Sample Input 0
3
123
Sample Output 0
For example:
Input Result
Correct
Marks for this submission: 1.00/1.00.
120
Question 3
Correct
For example:
Input Result
1,2,3,5,8 False
6
3,5,9,45,42 True
42
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
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
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
Correct
Marks for this submission: 1.00/1.00.
122
[Link]/moodle/mod/quiz/[Link]?attempt=218302&cmid=604 6/8
Question 5
Correct
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
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
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
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.
5 1 2 4 5 8 1 2 4 5 8
5 1 4 2 8
Correct
Marks for this submission: 1.00/1.00.
125
Question 2
Correct
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
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
Correct
Marks for this submission: 1.00/1.00.
◄ Week 11_MCQ
Jump to...
126