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

Practical Computer 1-30

The document contains a series of practical programming exercises, each labeled with a practical number from 6 to 30. These exercises cover various topics such as finding the greatest number, calculating net salary, checking for prime numbers, and manipulating strings and lists. Each exercise includes input prompts and corresponding logic to achieve the desired outcomes.

Uploaded by

hharshverma777
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Practical Computer 1-30

The document contains a series of practical programming exercises, each labeled with a practical number from 6 to 30. These exercises cover various topics such as finding the greatest number, calculating net salary, checking for prime numbers, and manipulating strings and lists. Each exercise includes input prompts and corresponding logic to achieve the desired outcomes.

Uploaded by

hharshverma777
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Practicalnumber===6

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:
greatest = num1
elif num2 >= num1 and num2 >= num3:
greatest = num2
else:
greatest = num3
print("The greatest number is:", greatest)

Practicalnumber===7

base_salary = float(input("Enter your salary: "))


years_of_service = int(input("Enter your years of service: "))

if 5 < years_of_service < 10:


hra = base_salary * 0.12
da = base_salary * 0.18
elif 10 <= years_of_service < 20:
hra = base_salary * 5.90
da = base_salary * 0.10
elif years_of_service >= 20:
hra = base_salary * 0.20
da = base_salary * 0.25

net_salary = base_salary + hra + da


print("The net salary is:{:.2f}".format(net_salary))

Practicalnumber===8
number1 = int(input("Enter the first integer: "))
number2 = int(input("Enter the second integer: "))
number3 = int(input("Enter the third integer: "))

for number in [number1, number2, number3]:


if number % 10 == 4:
print(f"{number} ends with four")
elif number % 10 == 8:
print(f"{number} ends with eight")
else:
print(f"{number} ends with neither")

Practicalnumber===9
temperature = float(input("Enter the temperature: "))
unit = input("enter the unit of temperature (c for celsius, f for
fahrenheit:)")
if unit == 'c':

converted_temperature = (temperature * 9/5) + 32


print(f"{temperature}°C is equal to {converted_temperature:.2f}°F")
elif unit == 'F':

converted_temperature = (temperature - 32) * 5/9


print(f"{temperature}°F is equal to {converted_temperature:.2f}°C")
else:
print("Invalid unit! Please enter 'c' for Celsius or 'f' for Fahrenheit.")

Practicalnumber===10
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

if num2 == 0:
print("The second number cannot be zero.")
else:

if num1 % num2 == 0:
print(f"{num1} is divisible by {num2}.")
else:
print(f"{num1} is not divisible by {num2}.")

Practicalnumber===11
start = int(input("Enter the start of the range(a): "))
end = int(input("Enter the end of the range(b): "))

sum = 0
for num in range(start, end + 1):
sum += num

print("The sum of natural number from 15 to 20 is:", sum)

Practicalnumber===12

start = int(input("Enter the start of the range: "))


end = int(input("Enter the end of the range: "))

for number in range(start, end + 1):


if number % 2 != 0:
print(number)

Practicalnumber===13

number = int(input("Enter a non-negative integer: "))


factorial = 1
for i in range(1, number + 1):
factorial *= i
print(f"The factorial of {number} is {factorial}.")

Practicalnumber===14

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


print(f"The factors of {number} are:")
for i in range(1, number + 1):
if number % i == 0:
print(i)

Practicalnumber===15

number = int(input("Enter a number to check if it is prime : "))


is_prime = True
if number < 2:
is_prime = False
else:
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
is_prime = False
break
if is_prime:
print(f"{number} is a prime number.")
else:
print(f"{number} is not a prime number.")

Practicalnumber===16
str = input("Enter a string: ")

if str==str[::-1]:
print("string is a palindrome")
else:
print("string is not a palindrome")

Practicalnumber===17
number=int(input("enter the number:"))

sum1=0

for i in range(1,number):

if(number%1==0):

sum1=sum1+i

if(sum1==number):

print(number,"the number is perfect")

else:

print(number,"the number is not perfect")

Practicalnumber===18
start = int(input("Enter the start of the range: "))

end = int(input("Enter the end of the range: "))

print("Armstrong numbers between", start, "and", end, ":")

for num in range(start, end + 1):

power = len(str(num))

total = sum(int(digit) ** power for digit in str(num))

if num == total:
print(num)

Practicalnumber===19
sentence = input("Enter a sentence: ")

word = input("Enter a word to find: ")

words = sentence.split()
count = words.count(word)

if count > 0:

print(f"The word '{word}' exists and appears {count} times.")

else:

print(f"The word '{word}' does not exist in the sentence.")

Practicalnumber===20
formula = input("Enter a formula: ")

open_count = formula.count('(')

close_count = formula.count(')')

if open_count == close_count:

print("The formula has balanced parentheses.")

else:
print("The formula does not have balanced parentheses.")

Practicalnumber===21
num = [3, 1, 4, 2]
dnum = [4, 2, 5, 3]
smallest_fraction = None
smallest_index = None
for i in range(len(num)):
fraction = num[i] / dnum[i]
if smallest_fraction is None or fraction < smallest_fraction:
smallest_fraction = fraction
smallest_index = i
print(f"The smallest fraction is
{num[smallest_index]}/{dnum[smallest_index]} at index
{smallest_index}")

Practicalnumber===21
numbers = list(map(int, input("Enter the numbers: ").split()))
divisible_by_8 = [num for num in numbers if num % 8 == 0]

if divisible_by_8:
print("Numbers divisible by 8:", divisible_by_8)
else:
print("No numbers in the list are divisible by 8.")

Practicalnumber===22
sentence = input("Enter a sentence: ")
words = sentence.split()
word_count = len(words)
print("The number of words in the sentence is:", word_count)

Practicalnumber===23
sentence = input("Enter a sentence: ")
words = sentence.split()
word_count = len(words)
print("The number of words in the sentence is:", word_count)

Practicalnumber===24
paragraph = input("Enter a paragraph: ")
words = paragraph.split()
long_words = [word for word in words if len(word) > 6]
print("Words with more than 6 characters:", long_words)

Practicalnumber===25
elements = input("Enter the elements of the list: ").split()
shifted_list = [elements[-1]] + elements[:-1]
print("List after shifting:", shifted_list)

Practicalnumber===26
pairs = [(2, 4), (4, 2), (9, 8), (12, 10)]

count = 0

for a, b in pairs:

if a % 2 == 0 and b % 2 == 0:

count += 1

print(count)
Practicalnumber===27
marks = []
for i in range(5):
print(f"Enter marks for student {i + 1}:")
subject1 = int(input("Subject 1: "))
subject2 = int(input("Subject 2: "))
subject3 = int(input("Subject 3: "))
marks.append((subject1, subject2, subject3))
marks = tuple(marks)
print("Marks:", marks)
for i in range(5):
total_marks = sum(marks[i])
average_marks = total_marks / 3
print(f"Student {i+1} - Total Marks: {total_marks}, Average Marks:
{average_marks:.2f}")

Practicalnumber===28
# Initialize an empty dictionary to store team data
teams = {}
# Repeatedly ask the user to enter team name, wins, and losses
while True:
team_name = input("Enter team name (or 'stop' to finish): ")
if team_name.lower() == 'stop':
break
wins = int(input(f"Enter number of wins for {team_name}: "))
losses = int(input(f"Enter number of losses for {team_name}: "))
teams[team_name] = [wins, losses]

# (a) Calculate and print the team's winning percentage


team_to_check = input("Enter a team name to check its winning
percentage: ")
if team_to_check in teams:
wins, losses = teams[team_to_check]
total_games = wins + losses
winning_percentage = (wins / total_games) * 100 if total_games > 0
else 0
print(f"The winning percentage for {team_to_check} is
{winning_percentage:.2f}%")
else:
print(f"{team_to_check} not found in the list.")

# (b) Create a list of the number of wins of each team


win_list = [team_data[0] for team_data in teams.values()]
print(f"List of wins for all teams: {win_list}")

# (c) Create a list of teams with winning records


winning_teams = [team for team, data in teams.items() if data[0] >
data[1]]
print(f"Teams with winning records: {winning_teams}")

Practicalnumber===29
products = {}

while True:
product_name = input("Enter product name (or 'yes' to no): ")
if product_name == 'yes':
break
price = input(f"Enter the price for {product_name}: ")
products[product_name] = price

print("\nThe products and their prices are:")


for product, price in products.items():
print(f"{product}: {price}")
while True:
query = input("Enter a product name to get its price (or 'done' to
exit): ")
if query == 'done':
break
if query in products:
print(f"The price of {query} is {products[query]}")
else:
print(f"{query} is not in the dictionary.")

Practicalnumber===30
d1 = {'a': [1, 2, 77], 'b': [44, 5, 6]}
d2 = {}
for key, value in d1.items():
d2[key] = sum(value)
print(d2)

You might also like