Python Programming Lab Certificate
Python Programming Lab Certificate
69
1A
07
24
SAI RAM " [Link] "24071A6953" Class ........... in the Laboratory "PYTHON
Problem 1:
Distance Between Two Points
Submitted Code:
import math
x1, y1, x2, y2 = map(float, input().split())
d = [Link](x2 - x1, y2 - y1)
print(f"{d:.2f}")
53
Testcase 1
Input:
0034
Expected Output:
5.00
Actual Output:
69
1A
5.00
07
Testcase 2
Input:
24
1145
Expected Output:
5.00
Actual Output:
5.00
Problem 2:
Compound Interest Calculator
Submitted Code:
P, R, T = map(float, input().split())
T = int(T)
A = P * (1 + R/100) ** T
print(f"{A:.2f}")
53
Testcase 1
Input:
1000 10 5
69
Expected Output:
1610.51
Actual Output:
1A
1610.51
07
Testcase 2
Input:
5000 8 3
24
Expected Output:
6298.56
Actual Output:
6298.56
Problem 3:
Person Details Input and Display
Submitted Code:
name = input()
address = input()
email = input()
phone = input()
print(f"Name: {name}")
53
print(f"Address: {address}")
print(f"Email: {email}")
print(f"Phone: {phone}")
Testcase 1
Input: 69
1A
John Doe
123 Main Street, Cityville
[Link]@[Link]
07
+1-555-1234
Expected Output:
Name: John Doe
24
53
Address: 456 Park Avenue, Townsburg
Email: alice_smith@[Link]
Phone: 9876543210
69
Actual Output:
Name: Alice Smith
Address: 456 Park Avenue, Townsburg
1A
Email: alice_smith@[Link]
Phone: 9876543210
07
24
Problem 4:
Character Type Classifier
Submitted Code:
ch = input()[0]
if ch >= '0' and ch <= '9':
print('Digit')
elif ch >= 'a' and ch <= 'z':
print('Lowercase Character')
53
elif ch >= 'A' and ch <= 'Z':
print('Uppercase Character')
else:
69
print('Special Character')
Testcase 1
1A
Input:
a
Expected Output:
07
Lowercase Character
Actual Output:
Lowercase Character
24
Testcase 2
Input:
5
Expected Output:
Digit
Actual Output:
Digit
Problem 5:
Fibonacci Sequence Generator
Submitted Code:
n = int(input())
a, b = 0, 1
count = 0
while count < n:
# Last term: print without trailing space
53
print(a, end=' ')
a, b = b, a + b
count += 1
Testcase 1
Input: 69
1A
5
Expected Output:
01123
07
Actual Output:
01123
24
Testcase 2
Input:
3
Expected Output:
011
Actual Output:
011
Problem 6:
Prime Numbers in Interval
Submitted Code:
start, end = map(int, input().split())
primes = []
for num in range(start, end + 1):
if num < 2:
continue
53
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
break
69
else:
[Link](num)
if primes:
1A
for p in primes:
print(p)
else:
07
Testcase 1
24
Input:
10 20
Expected Output:
11
13
17
19
Actual Output:
11
13
17
19
53
Actual Output:
2
3
69
5
7
1A
07
24
Problem 7:
Descending Number Triangle Pattern
Submitted Code:
# No input required; simply print the pattern
for row in range(1, 6):
num = 6 - row
print(" ".join([str(num)] * row))
53
Testcase 1
Input:
69
Expected Output:
5
44
1A
333
2222
11111
07
Actual Output:
5
44
24
333
2222
11111
Expected Output:
5
44
333
2222
53
11111
Actual Output:
5
69
44
333
2222
1A
11111
07
24
Problem 8:
LCM Calculator
Submitted Code:
import math
a, b = map(int, input().split())
lcm = a * b // [Link](a, b)
print(lcm)
53
Testcase 1
Input:
12 18
69
Expected Output:
36
Actual Output:
1A
36
07
Testcase 2
Input:
57
24
Expected Output:
35
Actual Output:
35
Problem 9:
Command Line Addition
Submitted Code:
# Read two integers from standard input and print their sum
a, b = map(int, input().split())
print(a + b)
Testcase 1
53
Input:
53
Expected Output:
69
8
Actual Output:
8
1A
Testcase 2
07
Input:
-2 7
Expected Output:
24
5
Actual Output:
5
Problem 10:
List and Tuple to Array Conversion
Submitted Code:
N, M = map(int, input().split())
list_input = input().split()
tuple_input = input().split()
# Function to detect type and format elements
def format_array(elements):
53
# Check if elements are all integers
if all([Link]('-').isdigit() for e in elements):
elements = [int(e) for e in elements]
69
return '[' + ' '.join(map(str, elements)) + ']'
else:
# Strings: wrap each element in quotes
1A
return '[' + ' '.join(f"'{e}'" for e in elements) + ']'
print(format_array(list_input))
print(format_array(tuple_input))
07
Testcase 1
Input:
24
34
123
4567
Expected Output:
[1 2 3]
[4 5 6 7]
Actual Output:
[1 2 3]
[4 5 6 7]
53
Actual Output:
['cat' 'dog']
['fish' 'bird' 'cow']
69
1A
07
24
Problem 11:
Common Values Between Two Arrays
Submitted Code:
N, M = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
# Use sets to find unique common values
common_values = sorted(set(arr1) & set(arr2))
53
if common_values:
print(' '.join(map(str, common_values)))
else:
69
print('No common values found')
Testcase 1
1A
Input:
45
1234
07
2 4 6 8 10
Expected Output:
24
24
Actual Output:
24
Testcase 2
Input:
33
123
456
Expected Output:
No common values found
Actual Output:
53
69
1A
07
24
Problem 12:
Create Tuple with Different Data Types
Submitted Code:
N = int(input())
elements = []
for _ in range(N):
value, dtype = input().split()
if dtype == 'i':
53
[Link](int(value))
elif dtype == 'f':
[Link](float(value))
69
elif dtype == 's':
[Link](value)
elif dtype == 'b':
1A
[Link](True if [Link]() == 'true' else False)
elif dtype == 'l':
# Convert comma-separated string into a list of integers
07
# Print outputs
print(result_tuple)
print(tuple(type(x) for x in result_tuple))
print(len(result_tuple))
53
Expected Output:
(42, 3.14, 'hello', True, [1, 2, 3])
(<class 'int'>, <class 'float'>, <class 'str'>, <class 'bool'>, <class 'list'>)
69
5
Actual Output:
(42, 3.14, 'hello', True, [1, 2, 3])
1A
(<class 'int'>, <class 'float'>, <class 'str'>, <class 'bool'>, <class 'list'>)
5
07
Testcase 2
Input:
24
3
100 i
world s
false b
Expected Output:
(100, 'world', False)
(<class 'int'>, <class 'str'>, <class 'bool'>)
3
Actual Output:
(100, 'world', False)
(<class 'int'>, <class 'str'>, <class 'bool'>)
3
Problem 13:
Python Tuple Creation and Operations
Submitted Code:
N = int(input())
values = input().split()
if N == 1:
# Create tuple from space-separated integers
result = tuple(int(x) for x in values)
53
elif N == 2:
# Create tuple with mixed data types (detect integers and string
s)
69
temp = []
for v in values:
if [Link]('-').isdigit():
1A
[Link](int(v))
else:
[Link](v)
07
result = tuple(temp)
elif N == 3:
# Create tuple from another sequence (here, we assume integers)
24
Testcase 1
Input:
1
12345
Expected Output:
53
(1, 2, 3, 4, 5)
<class 'tuple'>
5
69
Actual Output:
(1, 2, 3, 4, 5)
<class 'tuple'>
1A
5
07
Testcase 2
Input:
5
24
42
Expected Output:
(42,)
<class 'tuple'>
1
Actual Output:
(42,)
<class 'tuple'>
1
Problem 14:
Palindrome String Checker
Submitted Code:
import string
def palindrome(s):
# Convert to lowercase and remove non-alphanumeric characters
cleaned = ''.join([Link]() for ch in s if [Link]())
# Check if cleaned string is equal to its reverse
53
return cleaned == cleaned[::-1]
# Input
s = input()
69
print(palindrome(s))
Testcase 1
1A
Input:
A man, a plan, a canal: Panama
Expected Output:
07
True
Actual Output:
True
24
Testcase 2
Input:
race a car
Expected Output:
False
Actual Output:
False
Problem 15:
Greatest Common Divisor (GCD) Function
Submitted Code:
def gcd(a, b):
while b:
a, b = b, a % b
return a
if __name__ == "__main__":
53
a, b = map(int, input().split())
print(gcd(a, b))
69
Testcase 1
Input:
48 18
1A
Expected Output:
6
Actual Output:
07
6
24
Testcase 2
Input:
54 24
Expected Output:
6
Actual Output:
6
Problem 16:
Statistical Measures Calculator
Submitted Code:
from collections import Counter
# Input
N = int(input())
nums = list(map(int, input().split()))
# Mean
53
mean = round(sum(nums) / N, 2)
# Median
nums_sorted = sorted(nums)
69
if N % 2 == 1:
median = nums_sorted[N // 2]
else:
1A
median = round((nums_sorted[N//2 - 1] + nums_sorted[N//2]) / 2,
2)
# Mode
07
freq = Counter(nums)
max_count = max([Link]())
mode_candidates = [num for num, count in [Link]() if count == ma
24
x_count]
mode = min(mode_candidates)
# Output
print(f"{mean:.2f}")
if isinstance(median, float):
print(f"{median:.2f}")
else:
print(f"{median:.2f}") # Ensure 2 decimal places even for integ
er median
print(mode)
53
Actual Output:
2.33
2.50
69
3
1A
Testcase 2
Input:
5
07
11223
Expected Output:
1.80
24
2.00
1
Actual Output:
1.80
2.00
1
Problem 17:
Element Existence Check in Tuple
Submitted Code:
# Input reading
N = int(input())
elements = input().split()
T = input().strip()
search_value = input().strip()
53
# Convert elements based on type indicator
if T == 'i':
elements = [int(x) for x in elements]
69
search_value = int(search_value)
elif T == 'f':
elements = [float(x) for x in elements]
1A
search_value = float(search_value)
else: # string
elements = [x for x in elements]
07
# Convert to tuple
tup = tuple(elements)
# Check existence
24
if search_value in tup:
print("True")
print([Link](search_value))
print([Link](search_value))
else:
print("False")
print("Element not found")
print(0)
53
1
2
Actual Output:
69
True
1
2
1A
Testcase 2
07
Input:
4
apple banana orange grape
24
s
kiwi
Expected Output:
False
Element not found
0
Actual Output:
False
Element not found
0
Problem 18:
Check String Palindrome
Submitted Code:
import re
S = input()
S = [Link](r'[^A-Za-z0-9]', '', S).lower()
print("Yes" if S == S[::-1] else "No")
53
Testcase 1
Input:
A man, a plan, a canal: Panama
69
Expected Output:
Yes
Actual Output:
1A
Yes
07
Testcase 2
Input:
race a car
24
Expected Output:
No
Actual Output:
No
Problem 19:
Remove Word from String
Submitted Code:
T = input()
W = input()
words = [word for word in [Link]() if word != W]
print(' '.join(words) if words else 'Empty String')
53
Testcase 1
Input:
Hello world Hello Python Hello Java
69
Hello
Expected Output:
world Python Java
1A
Actual Output:
world Python Java
07
Testcase 2
Input:
24
Problem 20:
Generate N-Bit Binary Strings
Submitted Code:
def generate_binary(n, prefix=""):
if n == 0:
print(prefix)
return
generate_binary(n-1, prefix + "0")
53
generate_binary(n-1, prefix + "1")
# Main program
n = int(input())
69
generate_binary(n)
Testcase 1
1A
Input:
2
Expected Output:
07
00
01
10
24
11
Actual Output:
00
01
10
11
53
1
69
1A
07
24
Problem 21:
Implement Set Operations
Submitted Code:
n1 = int(input())
a = list(map(int, input().split()))
set_a = []
for x in a:
if x not in set_a:
53
set_a.append(x)
n2 = int(input())
b = list(map(int, input().split()))
69
set_b = []
for x in b:
if x not in set_b:
1A
set_b.append(x)
union = set_a.copy()
for x in set_b:
07
if x not in union:
[Link](x)
print(" ".join(map(str, sorted(union))) if union else "Empty")
24
53
34
12
125
69
Actual Output:
12345
34
1A
12
125
07
24
53
Empty
123
123456
69
Actual Output:
123456
Empty
1A
123
123456
07
24
Problem 22:
Is List Sorted Checker
Submitted Code:
def is_sorted(lst):
return all(lst[i] <= lst[i+1] for i in range(len(lst)-1))
n = int(input())
if n == 0:
lst = []
53
else:
lst = list(map(int, input().split()))
print(is_sorted(lst))
Testcase 1
Input: 69
1A
5
12345
Expected Output:
07
True
Actual Output:
True
24
Testcase 2
Input:
4
1324
Expected Output:
False
Actual Output:
False
Problem 23:
Duplicate Element Checker
Submitted Code:
def has_duplicates(lst):
seen = set()
for item in lst:
if item in seen:
return True
53
[Link](item)
return False
n = int(input())
69
if n == 0:
elements = []
else:
1A
elements = input().split()
# Convert numeric strings to int or float if possible
for i in range(len(elements)):
07
try:
if '.' in elements[i]:
elements[i] = float(elements[i])
24
else:
elements[i] = int(elements[i])
except ValueError:
pass # Keep as string if conversion fails
print(has_duplicates(elements))
53
Testcase 2
69
Input:
4
apple banana orange grape
1A
Expected Output:
False
Actual Output:
07
False
24
Problem 24:
Invert Dictionary
Submitted Code:
n = int(input())
orig_dict = {}
# Read input and store in original dictionary
for _ in range(n):
k, v = input().split()
53
# Convert numeric strings to int if possible
try:
k = int(k)
69
except ValueError:
pass
try:
1A
v = int(v)
except ValueError:
pass
07
orig_dict[k] = v
# Invert dictionary
inverted = {}
24
Testcase 1
53
Input:
3
1 apple
69
2 banana
3 apple
Expected Output:
1A
apple : [1, 3]
banana : 2
Actual Output:
07
apple : [1, 3]
banana : 2
24
53
Expected Output:
apple : [black, blue, red]
banana : green
69
cherry : yellow
Actual Output:
apple : [red, blue, black]
1A
banana : green
cherry : yellow
07
24
Problem 25:
Capitalize First Letter of Words
Submitted Code:
def capitalize_words(sentence):
result = []
words = [Link](' ')
for word in words:
if word == '':
53
[Link]('') # Preserve multiple spaces
continue
new_word = ''
69
for i, ch in enumerate(word):
ascii_val = ord(ch)
if i == 0:
1A
# Capitalize first letter if lowercase
if 97 <= ascii_val <= 122:
new_word += chr(ascii_val - 32)
07
else:
new_word += ch
else:
24
53
Testcase 2
Input:
69
PROGRAMMING is FUN
Expected Output:
Programming Is Fun
1A
Actual Output:
Programming Is Fun
07
24
Problem 26:
Remove Duplicates from List
Submitted Code:
def remove_duplicates(lst):
# Convert list to set to remove duplicates, then sort and return
unique_sorted = sorted(set(lst))
return unique_sorted
# Read input
53
n = int(input())
numbers = list(map(int, input().split()))
# Get unique sorted list
69
result = remove_duplicates(numbers)
# Print result
print(*result)
1A
Testcase 1
Input:
07
6
135371
Expected Output:
24
1357
Actual Output:
1357
Testcase 2
Input:
4
-2 -2 -2 -2
Expected Output:
-2
Actual Output:
53
69
1A
07
24
Problem 27:
Add Commas Between Characters
Submitted Code:
# Read input
s = input()
# Insert commas between characters
result = ','.join(s)
# Print the result
53
print(result)
Testcase 1
69
Input:
Apple
Expected Output:
1A
A,p,p,l,e
Actual Output:
A,p,p,l,e
07
Testcase 2
24
Input:
Hello123
Expected Output:
H,e,l,l,o,1,2,3
Actual Output:
H,e,l,l,o,1,2,3
Problem 28:
Cumulative Product Calculator
Submitted Code:
def cumulative_product(lst):
if not lst:
return "Empty list"
result = []
prod = 1
53
for num in lst:
prod *= num
[Link](prod)
69
return result
# Main program
n = int(input())
1A
if n == 0:
print("Empty list")
else:
07
Testcase 1
Input:
5
12345
Expected Output:
1 2 6 24 120
Actual Output:
1 2 6 24 120
53
69
1A
07
24
Problem 29:
List Reverse Function
Submitted Code:
def reverse(lst):
if not lst:
print("Empty list")
else:
print(*lst[::-1])
53
# Main program
n = int(input())
if n == 0:
69
print("Empty list")
else:
numbers = list(map(int, input().split()))
1A
reverse(numbers)
Testcase 1
07
Input:
5
12345
24
Expected Output:
54321
Actual Output:
54321
Testcase 2
Input:
0
Expected Output:
Empty list
Actual Output:
53
69
1A
07
24
Problem 30:
Matrix Printer
Submitted Code:
# Read dimensions
n, m = map(int, input().split())
# Read matrix elements
matrix = []
for _ in range(n):
53
row = list(map(int, input().split()))
[Link](row)
# Print the matrix
69
for row in matrix:
print(*row)
1A
Testcase 1
Input:
23
07
123
456
Expected Output:
24
123
456
Actual Output:
123
456
53
9 10
11 12
Actual Output:
69
78
9 10
11 12
1A
07
24
Problem 31:
Square Matrix Addition
Submitted Code:
# Read matrix size
n = int(input())
# Read first matrix
matrix1 = []
for _ in range(n):
53
row = list(map(int, input().split()))
[Link](row)
# Read second matrix
69
matrix2 = []
for _ in range(n):
row = list(map(int, input().split()))
1A
[Link](row)
# Add the two matrices
result = []
07
for i in range(n):
row = []
for j in range(n):
24
[Link](matrix1[i][j] + matrix2[i][j])
[Link](row)
# Print the resultant matrix
for row in result:
print(*row)
53
68
10 12
Actual Output:
69
68
10 12
1A
Testcase 2
Input:
07
3
123
456
24
789
987
654
321
Expected Output:
10 10 10
10 10 10
10 10 10
Actual Output:
10 10 10
10 10 10
10 10 10
Problem 32:
Factorial Calculator using Recursion
Submitted Code:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
53
# Main program
n = int(input())
print(factorial(n))
Testcase 1
Input: 69
1A
5
Expected Output:
120
07
Actual Output:
120
24
Testcase 2
Input:
0
Expected Output:
1
Actual Output:
1
Problem 33:
Factorial Calculator using Recursion
Submitted Code:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
53
# Main program
n = int(input())
print(factorial(n))
Testcase 1
Input: 69
1A
5
Expected Output:
120
07
Actual Output:
120
24
Testcase 2
Input:
0
Expected Output:
1
Actual Output:
1
Problem 34:
Square Matrix Multiplication
Submitted Code:
# Read matrix size
n = int(input())
# Read first matrix
matrix1 = []
for _ in range(n):
53
row = list(map(int, input().split()))
[Link](row)
# Read second matrix
69
matrix2 = []
for _ in range(n):
row = list(map(int, input().split()))
1A
[Link](row)
# Initialize result matrix with zeros
result = [[0] * n for _ in range(n)]
07
for k in range(n):
result[i][j] += matrix1[i][k] * matrix2[k][j]
# Print the resultant matrix
for row in result:
print(*row)
53
19 22
43 50
Actual Output:
69
19 22
43 50
1A
Testcase 2
Input:
07
3
123
456
24
789
987
654
321
Expected Output:
30 24 18
84 69 54
138 114 90
Actual Output:
30 24 18
84 69 54
138 114 90
Problem 35:
Simple Calculator Using Functions
Submitted Code:
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
53
return a * b
def divide(a, b):
if b == 0:
69
return "Error: Division by zero"
return a / b
# Main program
1A
num1 = float(input())
operator = input().strip()
num2 = float(input())
07
if operator == '+':
result = add(num1, num2)
elif operator == '-':
24
53
16.00
69
Testcase 2
Input:
20.0
1A
/
0.0
Expected Output:
07