Python PB 2 System
Python PB 2 System
➢ Output :
Create List is: [10, 20, 30, 40, 50]
After insert(2, 25): [10, 20, 25, 30, 40, 50]
After remove(30): [10, 20, 25, 40, 50]
After append(60): [10, 20, 25, 40, 50, 60]
Length of the list: 6
Popped element: 60
After pop(): [10, 20, 25, 40, 50]
After clear(): []
1
SYSTEM
Python Problem Sheet - 2 SYSTEM
➢ Output :
1) Dictionary items:
{'apple': 2, 'banana': 3, 'orange': 1, 'grape': 4}
2) Accessing items:
apples: 2
grapes: 4
3) Using get():
oranges: 1
watermelons: 0
4) Changing values:
Updated dic: {'apple': 2, 'banana': 5, 'orange': 1, 'grape': 4}
➢ Output :
Create Tupel is: (1, 2, 3, 4, 5)
1) Tuple after adding items: (1, 2, 3, 4, 5, 6, 7)
2) Length of the tuple: 5
3) 3 is present in the tuple.
4) Accessing items:
First item: 1
Last item: 5
2
SYSTEM
Python Problem Sheet - 2 SYSTEM
➢ Output :
Enter First Number : 20
Enter Second Number : 30
Enter Third Number : 10
Largest Number is : 30
3
SYSTEM
Python Problem Sheet - 2 SYSTEM
elif n==5:
day = "Friday"
elif n==6:
day = "Saturday"
elif n==7:
day = "Sunday"
else:
day = "Invalid Day Number! it's only less then 7"
print(f"Your Day Number : {n} and Day Name : {day}")
➢ Output :
Enter Number For Day : 7
Your Day Number : 7 and Day Name : Sunday
4
SYSTEM
Python Problem Sheet - 2 SYSTEM
➢ Output :
>>> Enter String : Khuhk
Khuhk String is Not palindrome
>>> Enter String : KhuhK
KhuhK String is palindrome
11.Write a Python function that takes two lists and returns True if they are
equal otherwise false.
➢ Program :
a = [1,2,3]
b = [1,2,3]
print(a == b)
➢ Output :
True
5
SYSTEM
Python Problem Sheet - 2 SYSTEM
print("*" * i)
➢ Output :
*
**
***
****
*****
➢ Output :
Enter Rows : 5
12345
1234
123
12
1
➢ Output :
Enter rows: 5
1
11
121
1331
6
SYSTEM
Python Problem Sheet - 2 SYSTEM
14641
➢ Output :
Enter Number : 5
1
23
456
7 8 9 10
11 12 13 14 15
➢ Output :
Enter Decimal Value : 10
Decimal Value is : 10
Binary Value is : 1010
Octal Value is : 12
Hexadecimal Value is : A
7
SYSTEM
Python Problem Sheet - 2 SYSTEM
# Main program
if __name__ == "__main__":
# Create a new deck of cards
deck = create_deck()
➢ Output :
Try to Run And Get Output
if c1 != r2:
raise ValueError("Number of columns in the first matrix must be
equal to the number of rows in the second matrix.")
for i in range(r1):
for j in range(c2):
for k in range(r2):
result_matrix[i][j] += matrix1[i][k] * matrix2[k][j]
return result_matrix
matrix1 = []
for i in range(r1):
row = []
for j in range(c1):
8
SYSTEM
Python Problem Sheet - 2 SYSTEM
➢ Output :
Enter the number of rows for the first matrix: 3
Enter the number of columns for the first matrix: 3
Enter element at position (1, 1): 10
Enter element at position (1, 2): 20
Enter element at position (1, 3): 15
Enter element at position (2, 1): 20
Enter element at position (2, 2): 30
Enter element at position (2, 3): 20
Enter element at position (3, 1): 50
Enter element at position (3, 2): 10
Enter element at position (3, 3): 20
Enter the number of rows for the second matrix: 3
Enter the number of columns for the second matrix: 3
Enter element at position (1, 1): 20
Enter element at position (1, 2): 4
Enter element at position (1, 3): 10
Enter element at position (2, 1): 20
Enter element at position (2, 2): 30
Enter element at position (2, 3): 20
Enter element at position (3, 1): 50
Enter element at position (3, 2): 60
Enter element at position (3, 3): 10
Result of matrix multiplication:
[1350.0, 1540.0, 650.0]
[2000.0, 2180.0, 1000.0]
[2200.0, 1700.0, 900.0]
9
SYSTEM
Python Problem Sheet - 2 SYSTEM
def is_armstrong_number(num):
num_str = str(num)
num_digits = len(num_str)
sum_of_digits = sum(int(digit) ** num_digits for digit in num_str)
return num == sum_of_digits
lower = int(input("Enter the lower limit of the interval: "))
upper = int(input("Enter the upper limit of the interval: "))
if lower > upper:
print("Invalid interval! The lower limit should be less than or equal to
the upper limit.")
else:
print("Armstrong numbers in the interval:")
for num in range(lower, upper + 1):
if is_armstrong_number(num):
print(num)
➢ Output :
Enter the lower limit of the interval: 100
Enter the upper limit of the interval: 1000
Armstrong numbers in the interval:
153
370
371
407
➢ Output :
Enter the first number: 10
Enter the second number: 5
The HCF/GCD of 10 and 5 is: 5
10
SYSTEM
Python Problem Sheet - 2 SYSTEM
➢ Output :
Enter the first number: 10
Enter the second number: 5
The LCM of 10 and 5 is: 10
➢ Output :
Enter a number to find its factors: 24
The factors of 24 are: [1, 2, 3, 4, 6, 8, 12, 24]
11
SYSTEM
Python Problem Sheet - 2 SYSTEM
elif choice == 5:
print("You are Exited !")
break
else:
print("Invalid Choice! Please try Again")
main()
➢ Output :
!! Simple Calculator !!
Operations:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter Operation Number (1/2/3/4/5): 1
Enter the first number: 20
Enter the second number: 30
Result: 50.0
➢ Output :
Enter a decimal number: 10
The binary representation of 10 is: 1010
12
SYSTEM