Practical Computer 1-30
Practical Computer 1-30
Practicalnumber===7
Practicalnumber===8
number1 = int(input("Enter the first integer: "))
number2 = int(input("Enter the second integer: "))
number3 = int(input("Enter the third integer: "))
Practicalnumber===9
temperature = float(input("Enter the temperature: "))
unit = input("enter the unit of temperature (c for celsius, f for
fahrenheit:)")
if unit == 'c':
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
Practicalnumber===12
Practicalnumber===13
Practicalnumber===14
Practicalnumber===15
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):
else:
Practicalnumber===18
start = int(input("Enter the start of the range: "))
power = len(str(num))
if num == total:
print(num)
Practicalnumber===19
sentence = input("Enter a sentence: ")
words = sentence.split()
count = words.count(word)
if count > 0:
else:
Practicalnumber===20
formula = input("Enter a formula: ")
open_count = formula.count('(')
close_count = formula.count(')')
if open_count == close_count:
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]
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
Practicalnumber===30
d1 = {'a': [1, 2, 77], 'b': [44, 5, 6]}
d2 = {}
for key, value in d1.items():
d2[key] = sum(value)
print(d2)