1. Write a program to print personal information.
# Program 1: Personal information
my_name=input("Enter your name:")
my_class=input("Enter your class:")
f_name=input("Enter your Father's name:")
s_name=input("Enter your school name:")
print("Hello World")
print("My name is ",my_name)
print("I'm studying in class ",my_class)
print("My Father's name is ",f_name)
print("My School's name is ",s_name)
Output:
Enter your name:Rahul
Enter your class:IX
Enter your Father's name:Manoj
Enter your school name:KENSRI School
Hello World
My name is Rahul
I'm studying in class IX
My Father's name is Manoj
My School's name is KENSRI School
2. Write a program for addition of two Numbers
# Program 2: Addition
num1 = int(input("Enter the first number:"))
num2 = int(input("Enter the second number:"))
sum_result = num1 + num2
print("The sum of", num1, "and", num2, "is:", sum_result)
Output:
Enter the first number: 15
Enter the second number: 25
The sum of 15 and 25 is: 40
3. Write a program to calculate Simple Interest if the principle_amount
= 2000 rate_of_interest = 4.5 time = 10
# Program 3: Simple Interest
principal_amount = 2000
rate_of_interest = 4.5
time = 10
simple_interest = (principal_amount * rate_of_interest * time) / 100
print("Simple Interest:“, simple_interest)
Output:
Simple Interest: 900.0
4. Write a program to find the area of a rectangle
length = float(input("Enter length of the rectangle: "))
breadth = float(input("Enter breadth of the rectangle: "))
area = length * breadth
print("Area of rectangle = ", area)
Output:
Enter length of the rectangle: 23
Enter breadth of the rectangle: 17
Area of rectangle = 391.0
5. Write a program to find the perimeter of a rectangle
length = float(input("Enter length of the rectangle: "))
breadth = float(input("Enter breadth of the rectangle: "))
perimeter = 2 * (length + breadth)
print("Perimeter of rectangle = ", perimeter)
Output:
Enter length of the rectangle: 23
Enter breadth of the rectangle: 17
Perimeter of rectangle = 80
6. Write a program to find the area of a Triangle
b = float(input('Enter base of a triangle: '))
h = float(input('Enter height of a triangle: '))
area = (b * h) / 2
print('The area of the triangle is ', area)
Output:
Enter base of a triangle: 34
Enter height of a triangle: 45
The area of the triangle is 765.0
7. Write a program to calculate the average marks of 3 subjects
a = int(input("Enter the marks of first subject: "))
b = int(input("Enter the marks of second subject: "))
c = int(input("Enter the marks of third subject: "))
total = a+b+c
avg = total/3
print("Total marks: ",total)
print("Average marks: ",avg)
Output:.
Enter the marks of first subject: 75
Enter the marks of second subject: 84
Enter the marks of third subject: 90
Total marks: 249
Average marks: 83.0
8. Write a program to Swap Two Variables
# Program 4: Swapping Variables
a = int(input(“Enter the first number:”))
b = int(input(“Enter the second number:”))
print("Before swap: a =", a, "b =", b)
temp = a
a=b
b = temp
print("After swap: a =", a, "b =", b)
Output:
Enter the first number: 10
Enter the second number: 20
Before swap: a = 10 b = 20
After swap: a = 20 b = 10
9. To print the following patterns using multiple print commands-
*
**
***
****
*****
for i in range(0, 5):
for j in range(0, i + 1):
print("* ", end=" ")
print()
Output:
*
* *
* * *
* * * *
* * * * *
[Link] print the table of 5 up to ten terms.
num = 5
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Output:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
[Link] a list in Python of children selected for science quiz with
following names Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha,
Kartik
Perform the following tasks on the list in sequence-
○ Print the whole list
○ Delete the name “Vikram” from the list
○ Add the name “Jay” at the end
○ Remove the item which is at the second position.
List=["Arjun","Sonakshi","Vikram","Sandhya","Sonal","Isha","Kartik"]
print(List)
[Link](2)
[Link]("Jay")
[Link](1)
print(List)
Output:
['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', ' Kartik ']
['Arjun', 'Sandhya', 'Sonal', 'Isha', ' Kartik ', 'Jay']
[Link] a list of first 10 even numbers, add 1 to each list item and
print the final list.
list=[2,4,6,8,10,12,14,16,18,20]
print("A list of first 10 even numbers")
print(list)
for i in range(0,len(list)) :
list[i]=list[i]+1
print("The final list")
print(list)
Output:
A list of first 10 even numbers
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
The final list
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
13. Program to check if a person can vote.
age = int(input("Enter age : "))
if age >= 18:
print("Eligible for Voting!")
else:
print("Not Eligible for Voting!")
Output:
Enter age : 30
Eligible for Voting!
[Link] Length of a String
# Program 14: Length of a String
word = "Computer"
length = len(word)
print("The word is:", word)
print("The length of the word is:", length)
Output:
The word is: Computer
The length of the word is: 8
[Link] a program to check if a Number is Positive, Negative, or Zero
# Program 15: Positive, Negative, or Zero Check
value = int(input("Enter a value : "))
if value > 0:
print(value, "is **Positive**.")
elif value < 0:
print(value, "is **Negative**.")
else:
print(value, "is **Zero**.")
Output:
Enter a value : -5
-5 is **Negative**.