0% found this document useful (0 votes)
7 views6 pages

UNIT 3 Python Programs-1

This document provides an introduction to Python programming, covering various print commands and basic operations such as arithmetic calculations, area and perimeter calculations, and list manipulations. It includes examples of using loops and conditional statements to perform tasks like checking eligibility to vote and calculating grades. Additionally, it demonstrates how to create patterns and manage lists through various list operations.

Uploaded by

Shweta Riddhi
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)
7 views6 pages

UNIT 3 Python Programs-1

This document provides an introduction to Python programming, covering various print commands and basic operations such as arithmetic calculations, area and perimeter calculations, and list manipulations. It includes examples of using loops and conditional statements to perform tasks like checking eligibility to vote and calculating grades. Additionally, it demonstrates how to create patterns and manage lists through various list operations.

Uploaded by

Shweta Riddhi
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

UNIT 3: INTRODUCTION TO PYTHON

PRINT Section

1. Print Personal Information

print("Name: Rahul Sharma")

print("Father's Name: Mr. Sharma")

print("Class: 9")

print("School Name: DPSG MRD")

2. Print Patterns using multiple print commands

print("*")

print("**")

print("***")

print("****")

3. Square of Number 7

print("Square of 7 is:", 7*7)

4. Sum of two numbers 15 and 20

print("Sum:", 15 + 20)

5. Convert length from kilometers to meters

km = 5

meters = km * 1000

print(km, "kilometers =", meters, "meters")

6. Table of 5 up to 5 terms

for i in range(1, 6):

print("5 x", i, "=", 5*i)


7. Simple Interest Calculation

principle_amount = 2000

rate_of_interest = 4.5

time = 10

simple_interest = (principle_amount * rate_of_interest * time) / 100

print("Simple Interest:", simple_interest)

8. Area and Perimeter of Rectangle

length = float(input("Enter length: "))

breadth = float(input("Enter breadth: "))

area = length * breadth

perimeter = 2 * (length + breadth)

print("Area:", area)

print("Perimeter:", perimeter)

9. Area of Triangle with Base & Height

base = float(input("Enter base: "))

height = float(input("Enter height: "))

area = 0.5 * base * height

print("Area of Triangle:", area)

10. Average Marks of 3 Subjects

m1 = float(input("Enter marks of subject 1: "))

m2 = float(input("Enter marks of subject 2: "))

m3 = float(input("Enter marks of subject 3: "))

avg = (m1 + m2 + m3) / 3

print("Average Marks:", avg)


11. Discounted Amount

price = float(input("Enter original price: "))

discount = float(input("Enter discount %: "))

final_price = price - (price * discount / 100)

print("Price after discount:", final_price)

12. Surface Area & Volume of Cuboid

l = float(input("Enter length: "))

b = float(input("Enter breadth: "))

h = float(input("Enter height: "))

surface_area = 2 * (l*b + b*h + l*h)

volume = l * b * h

print("Surface Area:", surface_area)

print("Volume:", volume)

LIST Section

13. Science Quiz Names

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

print(children)

[Link]("Vikram")

[Link]("Jay")

[Link](1) # remove item at 2nd position

print(children)

14. List num = [23,12,5,9,65,44]

num = [23,12,5,9,65,44]

print("Length:", len(num))

print("2nd to 4th elements:", num[1:4])

print("3rd to 5th using negative indexing:", num[-4:-1])


15. First 10 Even Numbers + 1

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

new_list = [x+1 for x in even_nums]

print(new_list)

16. Extend and Sort List

List_1 = [10,20,30,40]

List_1.extend([14,15,12])

List_1.sort()

print(List_1)

IF, FOR, WHILE Section

17. Check if a person can vote

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

if age >= 18:

print("Eligible to vote")

else:

print("Not eligible to vote")

18. Grade of Student

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

if marks >= 90:

print("Grade A")

elif marks >= 75:

print("Grade B")

elif marks >= 50:

print("Grade C")

else:

print("Grade D")
19. Check Positive, Negative or Zero

num = int(input("Enter number: "))

if num > 0:

print("Positive")

elif num < 0:

print("Negative")

else:

print("Zero")

20. First 10 Natural Numbers

for i in range(1, 11):

print(i, end=" ")

21. First 10 Even Numbers

for i in range(2, 21, 2):

print(i, end=" ")

22. Odd Numbers from 1 to n

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

for i in range(1, n+1):

if i % 2 != 0:

print(i, end=" ")

23. Sum of First 10 Natural Numbers

total = 0

for i in range(1, 11):

total += i

print("Sum:", total)
24. Sum of Numbers in a List

numbers = [5, 10, 15, 20]

total = sum(numbers)

print("Sum:", total)

25. To Print the pattern using for loop

# Print pattern using for loop for left side only

for i in range(1, 5): # Loop from 1 to 4

print("*" * i) # Print '*' i times

# for both side

rows = 5

for i in range(1, rows + 1):

# Left side: Increasing stars

left = "* " * i

# Right side: Decreasing stars

right = "* " * (rows - i + 1)

# Print them side by side with some spaces in between

print(left + " " * 8 + right)

You might also like