.
PYTHON
WORKSHEET .
CREDITS:
RUDRASISH BHATTACHARYA – CLASS 10A, ROLL NO: 25
1| P a g e
PROGRAM-1
Write a program to compute the simple interest. Accept the values of principal, rate and time from the
user.
CODE:
principal=float(input("Enter the principal amount (In Rs.): "))
rate=float(input("Enter the rate of interest (In Rs.): "))
time=float(input("Enter the time period in years: "))
simple_interest=(principal*rate*time)/100
print("The simple interest will be Rs.",simple_interest)
OUTPUT:
2| P a g e
PROGRAM-2
Write a program to check whether the given character is an uppercase letter or lowercase letter or a
digit or a special character.
CODE:
char = input("Enter a character: ")
if [Link]():
print("The character is an uppercase letter.")
elif [Link]():
print("The character is a lowercase letter.")
elif [Link]():
print("The character is a digit.")
else:
print("The character is a special character.")
OUTPUT:
3| P a g e
PROGRAM-3
Write a program to find the maximum number out of the given three numbers.
CODE:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
if num1 >= num2 and num1 >= num3:
largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3
print("The largest number is",largest)
OUTPUT:
4| P a g e
PROGRAM-4
An electric power distribution company charges its domestic consumers as follows:
Consumption Units Rate of Charge
0-100 Rs. 1 per unit
101-300 Rs. 100 plus Rs. 1.25 per unit in excess of 100
301-500 Rs. 350 plus Rs. 1.50 per unit in excess of 300
500 and above Rs. 650 plus Rs. 1.75 per unit in excess of 500
Write a program that read the customer number & power consumed and prints the amount to be paid
by the customer. Note that output should be well formatted.
CODE:
custno = int(input("Enter customer number: "))
units = int(input("Enter power consumed (units): "))
# Initialize the amount to be paid
amount = 0
# Calculate the amount based on consumption units
if units <= 100:
amount = units * 1
elif units <= 300:
amount = 100 + (units - 100) * 1.25
elif units <= 500:
amount = 350 + (units - 300) * 1.50
else:
amount = 650 + (units - 500) * 1.75
# Print the output in a well-formatted manner
print("\n----- Electricity Bill -----")
print("Customer Number : ", custno)
print("Units Consumed : “, units")
print("Amount to be Paid: Rs.",amount)
print("------------------------------")
OUTPUT:
5| P a g e
PROGRAM-5
Write a program to display summation of first N natural numbers.
For example:- if N =10 then output will be Sum 55.
CODE:
N = int(input("Enter a positive integer N: "))
Sum = 0
for i in range(1, N + 1):
Sum += i
print("The sum of the first", N, "natural numbers is", Sum)
OUTPUT:
6| P a g e
PROGRAM-6
Write a program to print a multiplication table of any positive integer N.
For example:- if N = 5 then output will be 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 .
CODE:
N = int(input("Enter a positive integer N: "))
for i in range(1, 11):
print(“The multiplication table of”, N,”:”, N * i, end=', ')
OUTPUT:
7| P a g e
PROGRAM-7
Write a program to create a list of students’ marks with user-defined values and find the maximum of
the marks.
For example:-
L = [85, 45, 90, 55, 65, 60]
then output will be:
Total marks= 400
Highest marks= 90
CODE:
marks =eval(input('Enter list of marks: '))
# Calculate the total marks
total = sum(marks)
# Find the highest mark
maxmarks =max(marks)
#display
print("Total marks: ",total)
print("Highest marks: ",maxmarks)
OUTPUT:
8| P a g e
PROGRAM-8
Write a program to create a list of numbers and find the sum of the even elements and the sum of the
odd elements present in it.
For example L = [ 5, 3, 4, 2, 7, 6] then output will be : Even Sum 12 Odd Sum 15 .
CODE:
L =eval(input("Enter list of numbers:"))
even_sum = 0
odd_sum = 0
for num in L:
if num % 2 == 0:
even_sum += num
else:
odd_sum += num
print("The sum of even number is",even_sum)
print("The sum of odd number is",odd_sum)
OUTPUT:
9| P a g e
10| P a g e
PROGRAM-9
Write a program to create a list of numbers and find the sum of the even location elements and the
sum of the odd location elements present in it.
For example: - L = [5, 3, 4, 2, 7, 6] then output will be: Even Sum 16, Odd Sum 11.
CODE:
nlist =eval(input(“Enter list of numbers:”))
evenpos, oddpos =0, 0
for i in range(len(nlist)):
if i% 2 ==0:
evenpos += nlist[i]
else:
oddpos += nlist[i]
print("The sum of even location elements is ",evenpos)
print("The sum of odd location elements is",oddpos)
OUTPUT:
11| P a g e
PROGRAM-10
Write a program to find the factorial value of N. Accept the value of N from the user.
For example:- factorial of 5 is 5 x 4 x 3 x 2 x 1 which is 120 .
CODE:
N = int(input("Enter the value of N: "))
fact = 1
for i in range(1, N + 1):
fact *= i
print("The factorial of”,N,”: ",fact)
OUTPUT:
12| P a g e