0% found this document useful (0 votes)
4 views11 pages

Sample Programs From List

The document contains a series of Python programming exercises designed for Class VIII students. Each exercise involves collecting user input, storing it in a list, and performing various operations such as calculating totals, averages, and filtering based on conditions. The exercises cover topics like marks, ages, prices, and number properties, providing practical coding experience.

Uploaded by

sb150296
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)
4 views11 pages

Sample Programs From List

The document contains a series of Python programming exercises designed for Class VIII students. Each exercise involves collecting user input, storing it in a list, and performing various operations such as calculating totals, averages, and filtering based on conditions. The exercises cover topics like marks, ages, prices, and number properties, providing practical coding experience.

Uploaded by

sb150296
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

Sample Programs from List

For Class- VIII


1. Write a Python program to collect the marks of 5 subjects
using a for loop, store them in a list, and perform the
following operations:
1. Calculate the total marks obtained.
2. Display the maximum marks obtained.
3. Display the minimum marks obtained.
marks = []
for i in range(1, 6):
m = int(input("Enter the marks for subject: "))
[Link](m)
total_marks = sum(marks)
max_marks = max(marks)
min_marks = min(marks)
print("Marks entered:", marks)
print("Total Marks:", total_marks)
print("Maximum Marks:", max_marks)
print("Minimum Marks:", min_marks)
2. Write a Python program to collect the ages of 5 family
members using a for loop, store them in a list, and perform the
following operations:
1. Calculate the average age.
2. Display the oldest age.
3. Display the youngest age.
ages = []
for i in range(1, 6):
a = int(input("Enter the age of family member : "))
[Link](a)
average_age = sum(ages) / len(ages)
oldest_age = max(ages)
youngest_age = min(ages)
print("Ages entered:", ages)
print("Average Age:", average_age)
print("Oldest Age:", oldest_age)
print("Youngest Age:", youngest_age)
3. Write a Python program to collect the prices of 5 items from
the user using a for loop, store them in a list, and perform the
following operations:
1. Calculate the total cost.
2. Display the most expensive item price.
3. Display the least expensive item price.
prices = []
for i in range(1, 6):
price = float(input("Enter the price of item : "))
[Link](price)
total_cost = sum(prices)
most_expensive = max(prices)
least_expensive = min(prices)
print("Prices entered:", prices)
print("Total Cost:", total_cost)
print("Most Expensive Item Price:", most_expensive)
print("Least Expensive Item Price:", least_expensive)
4. Write a Python program to collect 10 numbers from the user
using a for loop, store them in a list, and perform the following
operations:
1. Print only the even numbers from the list.
2. Calculate and display the sum of the even numbers.
numbers = []
s=0
for i in range(1, 11):
n= int(input("Enter number : "))
[Link](n)
print("Numbers entered:", numbers)
print("Even Numbers:")
for i in numbers:
if i % 2 == 0:
print(i)
s=s+i
print("Sum of Even Numbers:", s)
5. Write a Python program to collect 10 numbers from the user
using a for loop, store them in a list, and perform the following
operations:
1. Print all the multiples of 3 from the list.
2. Calculate and display the sum of these multiples.
numbers = []
s=0
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
print("Numbers entered:", numbers)
print("Multiples of 3:")
for i in numbers:
if i % 3 == 0:
print(i)
s=s+i
print("Sum of Multiples of 3:", s)
6. Write a Python program to collect 10 numbers from the user
using a for loop, store them in a list, and perform the following
operations:
1. Print only the numbers greater than 50 from the list.
2. Calculate and display the sum of these numbers.
numbers = []
s=0
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
print("Numbers entered:", numbers)
print("Numbers Greater Than 50:")
for i in numbers:
if i > 50:
print(i)
s=s+i
print("Sum of Numbers Greater Than 50:", s)
7. Write a Python program to collect 10 numbers from the user
using a for loop, store them in a list, and perform the following
operations:
1. Print only the numbers that are divisible by both 2 and 3.
2. Calculate and display the sum of these numbers.
numbers = []
s=0
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
print("Numbers entered:", numbers)
print("Numbers Divisible by 2 and 3:")
for i in numbers:
if i % 2 == 0 and i % 3 == 0:
print(i)
s=s+i
print("Sum of Numbers Divisible by 2 and 3:", s)
8. Write a Python program to collect 10 numbers from the user
and calculate:
1. The sum of all positive numbers.
2. The sum of all negative numbers.
numbers = []
positive_sum = 0
negative_sum = 0
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
for num in numbers:
if num > 0:
positive_sum= positive_sum + num
elif num < 0:
negative_sum=negative_sum +num
print("Numbers entered:", numbers)
print("Sum of Positive Numbers:", positive_sum)
print("Sum of Negative Numbers:", negative_sum)
[Link] a Python program to collect 10 numbers from the user,
calculate the average, and display all numbers greater than the
average.
numbers = []
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
average = sum(numbers) / len(numbers)
print("Numbers entered:", numbers)
print("Average:", average)
for num in numbers:
if num > average:
print(num)
10. Write a Python program to collect 10 numbers from the user,
store them in a list, and print the square of each number.
numbers = []
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
print("Numbers entered:", numbers)
for num in numbers:
print(num ** 2)
11. Write a Python program to collect 10 numbers from the user
and print the numbers that lie between two user-specified values
(inclusive).
numbers = []
for i in range(1, 11):
n = int(input("Enter number: "))
[Link](n)
lower_limit = int(input("\nEnter the lower limit: "))
upper_limit = int(input("Enter the upper limit: "))
for num in numbers:
if num>=lower_limit and num<=upper_limit:
print(num)

You might also like