0% found this document useful (0 votes)
2 views

x-practical

The document contains a series of programming exercises aimed at practicing basic concepts in Python. It includes tasks such as calculating net run rate, checking character types, finding maximum numbers, calculating electric power charges, checking for Armstrong numbers, generating multiplication tables, creating patterns, managing student marks, swapping list elements, and counting frequencies of list elements. Each exercise is presented with a code snippet that demonstrates the solution.

Uploaded by

billubilota6969
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)
2 views

x-practical

The document contains a series of programming exercises aimed at practicing basic concepts in Python. It includes tasks such as calculating net run rate, checking character types, finding maximum numbers, calculating electric power charges, checking for Armstrong numbers, generating multiplication tables, creating patterns, managing student marks, swapping list elements, and counting frequencies of list elements. Each exercise is presented with a code snippet that demonstrates the solution.

Uploaded by

billubilota6969
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
You are on page 1/ 12

lOMoARcPSD|52206100

X practical

Computer Science (Kendriya Vidyalaya Barrackpore)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Billu bilota ([email protected])
lOMoARcPSD|52206100

1. Write a program to compute the net run rate.

runs_scored = int(input("Enter total runs scored: "))


overs_batted = float(input("Enter total overs batted: "))
runs_conceded = int(input("Enter total runs conceded: "))
overs_bowled = float(input("Enter total overs bowled: "))

net_run_rate = (runs_scored / overs_batted) - (runs_conceded /


overs_bowled)

print("Net Run Rate:", net_run_rate)

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

2.Write a program to check whether the given character is an


uppercase letter or lowercase letter or a digit or a special character.

char = input("Enter a character: ")

if char.isalpha():
if char.isupper():
print(char, "is an uppercase letter.")
else:
print(char, "is a lowercase letter.")
elif char.isdigit():
print(char, "is a digit.")
else:
print(char, "is a special character.")

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

3.

Write a program to find the maximum number out of the given three
numbers.

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))

if num1 >= num2 and num1 >= num3:


max_num = num1
elif num2 >= num1 and num2 >= num3:
max_num = num2
else:
max_num = num3

print("The maximum number is:", max_num)

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

4.

1. An electric power distribution company charges its domestic consumers as


follows:

Consumption Units Rate of Charge

0-100 Rs. 1 per unit

101-300 Rs. 100 plus Rs. 1.25 per unit in excess of 10

301-500 Rs. 350 plus Rs. 1.50 per unit in excess of 30

500 and above Rs. 650 plus Rs. 1.75 per unit in excess of 50

Write a program that read the customer number & power


consumed and prints the amount to be paid by the customer. Note
that output should be well formatted.

customer_number = input("Enter customer number: ")


consumed_units = float(input("Enter power consumed (in units): "))

# Calculate the amount to be paid based on consumption units


if consumed_units <= 100:

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

amount = consumed_units * 1
elif 101 <= consumed_units <= 300:
amount = 100 + (consumed_units - 100) * 1.25
elif 301 <= consumed_units <= 500:
amount = 350 + (consumed_units - 300) * 1.50
else:
amount = 650 + (consumed_units - 500) * 1.75

print("Customer Number:", customer_number)


print("Power Consumed (in units):", consumed_units)
print("Amount to be Paid: Rs.", amount)

5.
Write a program to check whether the entered number is Armstrong
or not.

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

num_str = str(number)

num_digits = len(num_str)

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

sum_of_digits = sum(int(digit) ** num_digits for digit in num_str)

if sum_of_digits == number:
print(number, "is an Armstrong number.")
else:
print(number, "is not an Armstrong number.")\

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

6.
Write a program to print a multiplication table of the entered
number.

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

print("Multiplication Table of :",number)


for i in range(1, 11):
result = number * i
print("number x i = “,result)

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

7.
Write a program to generate the following pattern:
1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

current_number = 1

num_rows = 5

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


for j in range(i):
print(current_number, end=" ")
current_number += 1
print()

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

8.
Write a program to create a list of students’ marks with user-
defined values and find the maximum

num_students = int(input("Enter the number of students: "))

marks = [ ]

for i in range(num_students):
mark = float(input(f"Enter the mark for student {i+1}: "))
marks.append(mark)

max_mark = max(marks)

print("List of Marks:", marks)


print("Maximum Mark:", max_mark)

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

9.
Write a program to create a list of numbers and swap the content
with the next value divisible by 5.

num_elements = int(input("Enter the number of elements in the list: "))

numbers = []

for i in range(num_elements):
num = int(input("Enter number: "))
numbers.append(num)

for i in range(num_elements - 1):


if numbers[i] % 5 == 0:
numbers[i], numbers[i+1] = numbers[i+1], numbers[i]

print("Updated List:", numbers)

Downloaded by Billu bilota ([email protected])


lOMoARcPSD|52206100

10.
Write a program to count the frequency of every element in a given
list

elements_input = input("Enter elements separated by spaces: ")

elements = elements_input.split()

frequency = {}

for element in elements:


if element in frequency:
frequency[element] += 1
else:
frequency[element] = 1

print("Frequency of Elements:")
for element, count in frequency.items():
print(element, ":", count)

Downloaded by Billu bilota ([email protected])

You might also like