0% found this document useful (0 votes)
15 views3 pages

Python Practice Worksheet 2

Uploaded by

ashvita2008
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)
15 views3 pages

Python Practice Worksheet 2

Uploaded by

ashvita2008
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

Python Practice Worksheet – Term 1 Extra Practice

Q1. Write a Python program to input marks of 3 subjects,


calculate percentage, and print grade.
marks = []
for i in range(3):
m = int(input(f"Enter marks of subject {i+1}: "))
[Link](m)

total = sum(marks)
perc = total / 3

print("Total:", total)
print("Percentage:", perc)

if perc >= 90:


print("Grade A")
elif perc >= 75:
print("Grade B")
elif perc >= 50:
print("Grade C")
else:
print("Grade D")

Q2. Write a Python program to print first 15 natural numbers


using while loop.
i = 1
while i <= 15:
print(i, end=" ")
i += 1

Q3. Explain any three string functions with examples.


text = "Python Programming"

# upper() - converts to uppercase


print([Link]())

# lower() - converts to lowercase


print([Link]())

# replace() - replace substring


print([Link]("Python", "Java"))

Q4. A teacher stores names of students in a list. Write Python


code to: (i) display all names, (ii) count total students, (iii) display
names in reverse order.
students = ["Amit", "Riya", "Karan", "Meera"]
print("All names:", students)
print("Total students:", len(students))
print("Reverse order:", list(reversed(students)))

Q5. Write a Python program to create a dictionary of 3 students


with names as keys and marks as values. Display (i) all key-value
pairs, (ii) student with highest marks.
marks = {"Amit": 88, "Riya": 95, "Karan": 67}
print("All students:", marks)
topper = max(marks, key=[Link])
print("Highest marks:", topper, "with", marks[topper])

Q6. Consider list = [12, 45, 67, 89, 23]. Write Python code to: (i)
display even numbers, (ii) display sum of numbers, (iii) sort the
list, (iv) display last 3 elements.
nums = [12, 45, 67, 89, 23]
evens = [n for n in nums if n % 2 == 0]
print("Even numbers:", evens)
print("Sum:", sum(nums))
[Link]()
print("Sorted list:", nums)
print("Last 3 elements:", nums[-3:])

Q7. Write a Python program to input 10 numbers in a list and


display: (i) sum of numbers, (ii) count of positive numbers, (iii)
largest number, (iv) smallest number, (v) list in reverse order.
nums = []
for i in range(10):
n = int(input("Enter number: "))
[Link](n)
print("List:", nums)
print("Sum:", sum(nums))
positives = len([n for n in nums if n > 0])
print("Positive count:", positives)
print("Largest:", max(nums))
print("Smallest:", min(nums))
print("Reverse order:", list(reversed(nums)))

Q8. Write a program to create a dictionary of products with names


as keys and prices as values. Display (i) all items, (ii) product with
highest price, (iii) average price.
products = {"Pen": 10, "Book": 50, "Bag": 700}
print("All products:", products)
costliest = max(products, key=[Link])
print("Highest price product:", costliest, "with price", products[costliest])
avg = sum([Link]())/len(products)
print("Average price:", avg)

Q9. A school awards scholarships based on marks: ≥90 → ■5000,


75–89 → ■3000, 60–74 → ■2000, <60 → ■1000. Write a program to
input marks of a student and print scholarship amount.
marks = int(input("Enter marks: "))
if marks >= 90:
print("Scholarship = ■5000")
elif marks >= 75:
print("Scholarship = ■3000")
elif marks >= 60:
print("Scholarship = ■2000")
else:
print("Scholarship = ■1000")

You might also like