0% found this document useful (0 votes)
12 views9 pages

To Print Personal Information Like Name, Father's Name, Class, School Name

The document contains a series of Python programming tasks that demonstrate various functionalities such as printing personal information, calculating mathematical operations, manipulating lists, and implementing control structures. Each task includes code snippets along with expected outputs, covering topics like simple interest, area calculations, and user input handling. Overall, it serves as a practical guide for beginners to learn basic programming concepts in Python.

Uploaded by

maramdilip1982
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

To Print Personal Information Like Name, Father's Name, Class, School Name

The document contains a series of Python programming tasks that demonstrate various functionalities such as printing personal information, calculating mathematical operations, manipulating lists, and implementing control structures. Each task includes code snippets along with expected outputs, covering topics like simple interest, area calculations, and user input handling. Overall, it serves as a practical guide for beginners to learn basic programming concepts in Python.

Uploaded by

maramdilip1982
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. To print personal information like Name, Father's Name, Class, School Name.

Name="Vickram"
FName="Robert"
Sclass=9
Sch_Name="The Hyderabad Public School"
print (" *** PERSONAL INFORMATION *** ")
print ("Student Name : ",Name)
print ("Father's Name : ",FName)
print ("Class : ",Sclass)
print ("School Name : ",Sch_Name)

Output
*** PERSONAL INFORMATION ***
Student Name : Vickram
Father's Name : Robert
Class : 9
School Name : The Hyderabad Public School

2. To print the following patterns using multiple print commands:

a) print ("*")
print ("**")
print ("***")
print ("****")
print ("*****")

b) print ("*****")
print (" ****")
print (" ***")
print (" **")
print (" *")
3. To find square of number 7
N=7
print("Square of",N,"is:",N**2)

Output
Square of 7 is: 49

4. To find the sum of two numbers 15 and 20.


N1=15
N2=20
Print ("The sum of two numbers is :",N1+N2)

Output
The sum of two numbers is : 35

5. To convert length given in kilometers into meters.


Length=2.5
print ("Length given in kilometers is :",Length,"kms")
print ("Length converted in meters is :",Length*1000,"meters")

OutPut:
Length given in kilometers is : 2.5 kms
Length converted in meters is : 2500.0 meters

6. To print the table of 4 up to five terms.


N=5
print ("The table of 5 upto 5 terms are: ")
print (N,"x",1,"=",N*1)
print (N,"x",2,"=",N*2)
print (N,"x",3,"=",N*3)
print (N,"x",4,"=",N*4)

output:
The table of 5 upto 5 terms are:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
7. To calculate Simple Interest if the principle_amount = 2000 rate_of_interest =
4.5 time = 10.

P=2000;R=4.5;T=10
SI=(P*R*T)/100
print ("Simple Interest is : ",SI)

output:
Simple Interest is : 900.0

8. To calculate Area and Perimeter of a rectangle.

Length=int (input ("Enter Length : "))


Breadth=int (input ("Enter Breadth : "))
print ("Area of Rectangle is : ",Length*Breadth)
print ("Perimeter of Rectangle is : ",2*(Length+Breadth))

Output:
Enter Length : 10
Enter Breadth : 20
Area of Rectangle is : 200
Perimeter of Rectangle is : 60

9. To calculate Area of a triangle with Base and Height.

Base=int (input ("Enter Base :"))


Height=int (input ("Enter Height : "))
print ("Area of Triangle is : ", (1/2)*Base*Height)

Output:

Enter Base :10


Enter Height : 15
Area of Triangle is : 75.0
10. To calculating average marks of 3 subjects.

Eng=float (input ("Enter Eng Marks : "))


Maths=float (input ("Enter Maths Marks : "))
Science=float (input ("Enter Science Marks : ") )
print ("Average of 3 subjects is : ", round ( (Eng+Maths+Science)/3,2))

Output:
Enter Eng Marks : 80
Enter Maths Marks : 96
Enter Science Marks : 90
Average of 3 subjects is : 88.67

11. To calculate discounted amount with discount %.

Amt=int (input ("Enter an Amount : ") )

Discount=int (input ("Enter Discount : ") )

print ("The discounted amount is : ", Amt-Discount)


print ("The discount % is : ", (Discount/Amt) *100)

Output:

Enter an Amount : 1000


Enter Discount : 24
The discounted amount is : 976
The discount % is : 2.4

12. To calculate Surface Area and Volume of a Cuboid.


Length=int (input ("Enter Length : "))
Breadth=int (input ("Enter Breadth : "))
Height=int (input ("Enter Height : "))
Volume=Length*Breadth*Height
print ("Volume of Cuboid is : ",Volume)
Surface_Area=2*((Length*Breadth)+(Breadth*Height)+(Length*Height))
print ("Surface Area of Cuboid is : ",Surface_Area)
Output:
Enter Length : 10
Enter Breadth : 8
Enter Height : 5
Volume of Cuboid is : 400
Surface Area of Cuboid is : 340

13. Create 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-
a) Print the whole list
b) Delete the name "Vikram" from the list
c) Add the name "Jaya" at the end
d) Remove the item which is at the second position.

Names=["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]


print (Names)
[Link] ("Vikram")
print (Names)
[Link] ("Jaya")
print (Names)
[Link] (1)
print (Names)

Output:
['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jaya']
['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jaya']

14. Create a list num=[23,12,5,9,65,44]


a) Print the length of the list
b) Print the elements from second to fourth position using positive indexing
c) Print the elements from position third to fifth using negative indexing

L1=[23,12,5,9,65,44]
print (len (L1))
print (L1[1:4])
print (L1[-4 :- 1])
Output:
6
[12, 5, 9]
[5, 9, 65]

15. Create a list of first 10 even numbers, add 1 to each list item and print the
final list.

L1=[]
for x in range (2,21,2):
[Link] (x)
print (L1)
for i in range (len (L1)):
L1 [i]+=1
print (L1)

Output:

[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]


[3, 5, 7, 9, 11, 13, 15, 17, 19, 21]

16. Create a list List_1=[10,20,30,40]. Add the elements [14,15,12] using the
extend function. Now sort the final list in ascending order and print it.

List_1=[10,20,30,40]
List_1.extend([14,15,12])

List_1=sorted(List_1)
print (List_1)

Output:
[10, 12, 14, 15, 20, 30, 40]
17. Program to check if a person can vote or not.

Age=int (input ("Enter Age : "))


if Age>=18:
print ("The person can vote")
else:
print ("The person cannot vote")
print ("Wait for ",18-Age, "years")

Output:
Enter Age : 23
The person can vote
Enter Age : 12
The person cannot vote
Wait for 6 years

18. To check the grade of a student.

marks=float (input ("Enter marks out of hundred:"))


if 90 <= marks <= 100:
print ("Grade is A")
elif 75 <= marks <= 89.9:
print ("Grade is B")
elif 60 <= marks <= 74.9:
print ("Grade is C")
elif 45 <= marks <= 59.5:
print ("Grade is D")
elif 33 <= marks <= 44.9:
print ("Grade is E")
elif 0 <= marks <= 32.9:
print ("Grade is F")
else:
print ("Invalid Marks")

Output:

Enter marks out of hundred:78


Grade is B
19. Input a number and check if the number is positive, negative or zero and
display an appropriate message.

N=int (input ("Enter a number: "))


if N<0:
print(N," is a -ve number")
elif N == 0:
print (N," is entered")
else:
print (N," is a +ve number")

Output:
Enter a number: 8
8 is a +ve number

20. To print first 10 natural numbers.

for i in range (1,11):


print (i, end="!")

Output:
1!2!3!4!5!6!7!8!9!10!

21. To print first 10 even numbers.


for i in range (1,11):
print (2*i)
Output:
2
4
6
8
10
12
14
16
18
20
22. To print N odd numbers.

N=int(input("Enter the term : "))


for i in range(1,N+1):
print(2*i-1,end=",")

Output:
Enter the term : 7
1,3,5,7,9,11,13,

23. To print sum of first 10 natural numbers.

S=0
for i in range (1,11):
S+=i
print ("The sum is ",S)

Output:
The sum is 55
24. Program to find the sum of all numbers stored in a list.

S=0
for i in [1,2,3,4,5]:
S+=i
print ("The sum is ",S)

Output:
The sum is 15

You might also like