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

computer assignment

Class 11 program file

Uploaded by

cvt3zuuuyi
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)
9 views

computer assignment

Class 11 program file

Uploaded by

cvt3zuuuyi
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/ 39

Certificate

This is to certify that ___of class XI


has worked successfully under the supervision of
Mrs. during academic year 20__-__
on the “PROGRAM FILE” as per the guidelines issued by
Central Board of Secondary Education (CBSE).

Signature of Subject Teacher Signature of Principal

1
~I N D E X~
1. WAP to make a calculator having ‘+’ ,’-’ ,’*’, ‘/’, ‘//’, ‘%’ as operators
Input the numbers and operator from the user. Page no- 05

2. WAP to input the name and current age of the user and check in
which year the user will turn 100 years old. Page no- 07

3. WAP to input a text from the user and count the total number of
alphabets, spaces,words,uppercases,lowercases,numbers,special
characters in the text. Page no- 08

4. Generate the following patterns using nested loops: Page no- 12

5. WAP to input ur marks of five subjects display its average, total


marks of 5 subjects, percentage and grade acc. To the following table:
Page no- 14

6. WAP to input a list from the user and search an inputted element in
the list.Display its positive and negative index along with its occurence.
Page no- 16

7. Generate the following patterns using nested loops Page no- 18

8. Enter a string. Do you want to perform any case-related operations


on the string? Choose from the following options:
Uppercase,Lowercase,Capitalise,Title,Swapcase,Reverse: Page no- 19

9. WAP to convert a temp value into different scales: Page no- 22

10. Compute the greatest common divisor and least common multiple
of two integers. Page no- 24

2
11. Write a Python program that takes user input to create two
tuples, t1 and t2. Swap the content of the tuples, and display both
the original and swapped tuples. Page no- 25

12. Write a program to search an element in a tuple. Page no- 26

13. Write a Python program that allows the user to input integers to
create a tuple. Prompt the user to enter a specific integer for frequency
checking. Page no- 27

14. Write a program to enter names of employees and their salaries as


input and store them in a dictionary. Page no- 28

15. Write a program to enter name and percentage in a dictionary of n


number of students and display the information. Page no-29

16. WAP to calculate and display the frequency of words, letters, or


characters, along with the total character count in dict?" Page no- 30

17. WAP to input names of ‘n’ employees and their salary detail.
Page no- 32

18. Write a Python program that calculates the area and perimeter for a
chosen geometric shape. Page no- 34

19. Wap to roll 2 dices simultaneously, if the digits are same on


both the dices then declare the user as winner. Page no- 37

20. WAP to Check if a list is a palindrome. Page no- 39

3
1.WAP to make a calculator having ‘+’ ,’-’ ,’*’, ‘/’, ‘//’, ‘%’ as operators
Input the numbers and operator from the user.

# Get input from the user


a = int(input("Enter the first number: "))
opt = input("Enter the operator (+, -, *, /,//, %): ")
b = int(input("Enter the second number: "))

# Perform the selected operation and display the result


if opt == "+":
print(a, "+", b, "=", a + b) #sum of the nos.
elif opt == "-":
print(a, "-", b, "=", a - b) #subtraction of the nos.
elif opt == "*":
print(a, "*", b, "=", a * b) #product of the nos.
elif opt == "/":
print(a, "/", b, "=", a / b) #quotient w/ decimal
elif opt == "//":
print(a, "//", b, "=", a // b) #quotient w/o decimal
elif opt == "%":
print(a, "%", b, "=", a % b) #remainder of the nos.

else:
# Display an error message for invalid operations
print("Invalid operation. Please enter a valid operator (+, -
/,//, %).")

4
O/p

5
2.WAP to input the name and current age of the user and check in which
year the user will turn 100 years old.
{Write an appropriate msg regarding the same}

name=input('enter the name')


age=int(input('enter the age'))
current_year=int(input("enter the current year"))
year_100=current_year+(100-age)
print("hello,", name,".You'll turn 100 years old in the
year",year_100)

O/p

6
3.WAP to input a text from the user and count the total number of
alphabets, spaces,words,uppercases,lowercases,numbers,special
characters in the text.
{Write an appropriate msg regarding the same}

text = input('Enter a text: ')


size = len(text) #length of the inputted text
s = d = a = u = l = e = 0
sp=text.split() #every word will get separated

print('1 - Space')
print('2 - Digit')
print('3 - Alphabet')
print('4 - Uppercase')
print('5 - Lowercase')
print('6 - Special characters')
print('7 - Words')

choice = int(input('Enter your choice: '))

for i in range(0, size):


if choice == 1:
if text[i].isspace():
s += 1
elif choice == 2:
if text[i].isdigit():
d += 1
elif choice == 3:
if text[i].isalpha():
a += 1
elif choice == 4:
if text[i].isupper():
u += 1
elif choice == 5:
if text[i].islower():
l += 1
elif choice == 6:
if text[i].isalnum()!=True and text[i].isspace()!=True:
e += 1
else:
continue

7
if choice == 1:
print('Number of spaces:', s)
elif choice == 2:
print('Number of digits:', d)
elif choice == 3:
print('Number of alphabets:', a)
elif choice == 4:
print('Number of uppercase characters:', u)
elif choice == 5:
print('Number of lowercase characters:', l)
elif choice == 6:
print('Number of special characters:', e)
elif choice == 7:
print('Number of words:', len(sp)) #length of splitted
words
else:
print("Invalid choice. Enter a no. b\w '1,2,3,4,5,6,7'")

O/p

8
9
10
4.Generate the following patterns using nested loops:

Pattern-1
for i in range(1, 6):
print("*" * i)

O/p

Pattern-2
for i in range(5, 0, -1):
for j in range(1, i + 1):
print(j, end="")
print()

O/p

11
Pattern-3
for i in range(1, 6):
for j in range(1, i + 1):
print(chr(64 + j), end="")
print()

O/p

12
5.WAP to input ur marks of five subjects display its average, total marks of
5 subjects, percentage and grade acc. To the following table:

engmark=float(input("Enter your marks in English subject:"))


#Marks in english
biomark=float(input("Enter your marks in Biology subject:"))
#Marks in Bio
chemmark=float(input("Enter your marks in Chemistry
subject:")) #Marks in Chem
phymark=float(input("Enter your marks in Physics subject:"))
#Marks in phy
compmark=float(input("Enter your marks in Computer subject:"))
#Marks in comp
maxn=int(input('Enter maximum marks that can be obtained in
one subject:')) #Enter max marks of only 1 sub.
average=(engmark+biomark+chemmark+phymark+compmark)/5
total=(engmark+biomark+chemmark+phymark+compmark)
percent=(total/(maxn*5))*100
print('Average marks:',average)
print('percentage:',percent)
if percent>=91:
print("Your grade is A1")
elif percent>=81:
print("Your grade is A2")

13
elif percent>=71:
print("Your grade is B1")
elif percent>=61:
print("Your grade is B2")
elif percent>=51:
print("Your grade is C1")
elif percent>=41:
print("Your grade is C2")
elif percent>=33:
print("Your grade is D")
else :
print("Congratulations,You have failed ur examination:)")

O/p

14
6.WAP to input a list from the user and search an inputted element in the
list.
Display its positive and negative index along with its occurence.
l = [] # Empty list
range_list = int(input('Enter the range for your list: '))

# Input elements into the list


for i in range(range_list):
n = int(input('Enter an element for your list: '))
l.append(n)

num = int(input('Enter an element to SEARCH: '))

ind = [] #empty list


count = 0

for i in range(len(l)):
if l[i] == num:
ind.append(i)
count += 1

if len(ind) > 0: # If the list is not empty,the element is found


print('Element', num, 'is found at indices:', ind)
# Add negative indices
negative_ind = [i - len(l) for i in ind]
print('Negative indices:', negative_ind)
print('Number of times occurred:', count)
else:
print('Entered element not found')

15
O/p

16
7.Generate the following patterns using nested loops:

for i in range(1,6):
num=1
for j in range(6,0,-1):
if j>i:
print(' ',end='')
else:
print('*',end='')
print()

O/p

17
8.Enter a string. Do you want to perform any case-related operations on
the string? Choose from the following options:
Uppercase,Lowercase,Capitalise,Title,Swapcase,Reverse:

user_input = input("Enter a string: ")


if any(char.isalpha() for char in user_input):
print("Select an option:")

print("1. Uppercase")
print("2. Lowercase")
print("3. Capitalize")
print("4. Title")
print("5. Swapcase")
print("6. Reverse")
print("7. Exit")

choice = input("Enter your choice (1/2/3/4/5/6/7): ")

if choice == "1":
result = user_input.upper()
elif choice == "2":
result = user_input.lower()
elif choice == "3":
result = user_input.capitalize()
elif choice == "4":
result = user_input.title()
elif choice == "5":
result = user_input.swapcase()
elif choice == "6":
result = user_input[::-1]
elif choice == "7":
print("Exiting program. No changes made.")
else:
print("Invalid choice. No changes made.")

if choice in ["1", "2", "3", "4", "5", "6"]:


print("Original String: " + user_input)
print("Modified String: " + result)

else:
print("The input does not contain alphabets.")
18
O/p

19
20
9.Enter a temperature value. Choose a conversion:
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
3. Kelvin to Celsius
4. Celsius to Kelvin
Enter the corresponding number for your choice:

temperature = float(input("Enter a temperature value: "))


print("Choose a conversion:")
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
print("3. Kelvin to Celsius")
print("4. Celsius to Kelvin")
choice = input("Enter the corresponding no.for your choice: ")

if choice == "1":
converted_temperature = (temperature * 9/5) + 32
print(str(temperature) + " Celsius is equal to " +
str(converted_temperature) + " Fahrenheit.")
elif choice == "2":
converted_temperature = (temperature - 32) * 5/9
print(str(temperature) + " Fahrenheit is equal to " +
str(converted_temperature) + " Celsius.")
elif choice == "3":
converted_temperature = temperature - 273.15
print(str(temperature) + " Kelvin is equal to " +
str(converted_temperature) + " Celsius.")
elif choice == "4":
converted_temperature = temperature + 273.15
print(str(temperature) + " Celsius is equal to " +
str(converted_temperature) + " Kelvin.")
else:
print("Invalid choice. Please enter a valid number.")

21
O/p

22
10.Compute the greatest common divisor and least common multiple of
two integers.

# Input two integers


num1 = int(input('Enter the first integer: '))
num2 = int(input('Enter the second integer: '))

# Compute GCD
a, b = num1, num2
while b:
a, b = b, a % b
result_gcd = a

# Compute LCM
result_lcm = abs(num1 * num2) // result_gcd

# Display the results


print('The GCD of', num1, 'and', num2, 'is:', result_gcd)
print('The LCM of', num1, 'and', num2, 'is:', result_lcm)

O/p

23
11.Write a Python program that takes user input to create two tuples, t1
and t2. Prompt the user to enter values for each tuple, swap the
content of the tuples, and display both the original and swapped
tuples.

t1 = t2 = tuple()
n = int(input("Number of values in the first tuple: "))
for i in range(n):
a = int(input('Enter number: '))
t1 = t1 + (a,)
print('First tuple:', t1)
n = int(input("Number of values in the second tuple: "))
for i in range(n):
a = int(input('Enter number: '))
t2 = t2 + (a,)
print('Second tuple:', t2)

t1, t2 = t2, t1
print('After Swapping:')
print('First tuple:', t1)
print('Second tuple:', t2)

O/p

24
12.Write a program to search an element in a tuple.

t = ()
n = int(input("Size of the tuple: "))
for i in range(n):
a = int(input('Enter the number: '))
t = t + (a,)
print('Tuple:', t)

element = int(input('Enter number to be searched: '))


for i in range(len(t)):
if t[i] == element:
print(element, 'is available in the tuple at
position', i + 1)
break
else:
print(element, 'is not available in the tuple')
O/p

25
13.Write a Python program that allows the user to input integers to create a
tuple. After creating the tuple, prompt the user to enter a specific integer
for frequency checking. Output the frequency of the entered integer in
the tuple.

t = ()
n = int(input("Size of the tuple: "))
for i in range(n):
a = int(input('Enter the number: '))
t = t + (a,)

print('Tuple:', t)

element = int(input('Enter number for frequency check: '))


c = 0
for i in range(0, len(t)):
if t[i] == element:
c = c + 1

if c == 0:
print(element, 'not found in the tuple')
else:
print(element, 'found', c, 'times in the tuple')

O/p

26
14.Write a program to enter names of employees and their salaries as input
and store them in a dictionary.

employee_salary_dict = {}

while True:
employee_name = input("Enter employee name: ")
salary = int(input("Enter employee salary: "))

employee_salary_dict[employee_name] = salary

user_input = input("Do you want to quit? (Enter 'yes' to


quit): ")

if user_input.lower()== "yes" or user_input.lower()== "y":


break

print("Employee dictionary:", employee_salary_dict)

O/p

27
15.Write a program to enter name and percentage in a dictionary of n
number of students and display the information.

student_records = {}
number_of_students = int(input('Enter the no. of students: '))
i = 1

while i <= number_of_students:


student_name = input('Enter student name: ')
percentage = input('Enter percentage: ')
student_records[student_name] = percentage
i = i + 1

# Printing the details in tabular form


print("Name\t Percentage")
for student in student_records:
print(student, "\t", student_records[student])

28
16.Write a program to enter name and percentage in a dictionary of n
number of students and display the information.

input_string = input("Enter a string: ")


frequency = {}
character_count = 0

choice = input("Enter 'w' to count words, 'l' to count


letters, or 'c' to count characters: ")

if choice.lower() == 'w':
# Counting word frequency
words = input_string.split()
for item in words:
if item in frequency:
frequency[item] += 1
else:
frequency[item] = 1
elif choice.lower() == 'l':
# Counting letter frequency
for char in input_string:
if char.isalpha():
if char in frequency:
frequency[char] += 1
else:
frequency[char] = 1
character_count += 1
elif choice.lower() == 'c':
# Counting character frequency
for char in input_string:
if char in frequency:
frequency[char] += 1
else:
frequency[char] = 1
character_count += 1
else:
print("Invalid choice! Please enter 'w', 'l', or 'c'.")
# Displaying the frequency and character count
print("Frequency:")
for key, value in frequency.items():
print(key, '->', value)
print("Character count:", character_count)

29
O/p

30
17.Write a program to input names of ‘n’ employees and their salary details
like basic pay (bp), house rent ( hra ) , conveyance allowance(ca).
calculate the total salary of each employee.
[total salary = basic pay+house rent + conveyance allowance]

employee_data = {}
n = int(input("Enter the number of employees: "))

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


name = input("Enter name of employee " + str(i) + ": ")
basic_pay =float(input("Enter basic pay for " + name + ":
"))
house_rent =float(input("Enter house rent for " + name +
": "))
conveyance_allowance = float(input("Enter conveyance
allowance for " + name + ": "))

total_salary = basic_pay + house_rent +


conveyance_allowance

employee_data[name] = {
"Basic Pay": basic_pay,
"House Rent": house_rent,
"Conveyance Allowance": conveyance_allowance,
"Total Salary": total_salary
}

# Displaying the details in tabular form


print("\nEmployee Details:")
print("Name\tBasic Pay\tHouse Rent\tConveyance
Allowance\tTotal Salary")
for name, details in employee_data.items():
print(name + "\t" + str(details["Basic Pay"]) + "\t\t" +
str(details["House Rent"]) + "\t\t" +
str(details["Conveyance Allowance"]) + "\t\t" +
str(details["Total Salary"]))

31
O/p

32
18.Write a Python program that calculates the area and perimeter for a
chosen geometric shape. The program should provide the user with
options to select a shape (Circle, Square, Rectangle, Triangle) by
entering the corresponding number. After selecting a shape, the user will
input the required dimensions, and the program will display the
calculated area and perimeter.

import math

def circle_area(radius):
return math.pi * radius**2

def circle_perimeter(radius):
return 2 * math.pi * radius

def square_area(side):
return side**2

def square_perimeter(side):
return 4 * side

def rectangle_area(length, width):


return length * width

def rectangle_perimeter(length, width):


return 2 * (length + width)

def triangle_area(base, height):


return 0.5 * base * height

def triangle_perimeter(side1, side2, side3):


return side1 + side2 + side3

33
def main():
choice = int(input("Choose a shape:\n1. Circle\n2.
Square\n3. Rectangle\n4. Triangle\nEnter the corresponding
number: "))

if choice == 1:
radius = float(input("Enter the radius of circle: "))
print("Area:", circle_area(radius))
print("Perimeter:", circle_perimeter(radius))
elif choice == 2:
side = float(input("Enter the side length of the
square: "))
print("Area:", square_area(side))
print("Perimeter:", square_perimeter(side))
elif choice == 3:
length = float(input("Enter the length of the
rectangle: "))
width = float(input("Enter the width of the rectangle:
"))
print("Area:", rectangle_area(length, width))
print("Perimeter:", rectangle_perimeter(length,
width))
elif choice == 4:
base = float(input("Enter the base length of the
triangle: "))
height = float(input("Enter the height of the
triangle: "))
print("Area:", triangle_area(base, height))
side1 = float(input("Enter the length of side 1: "))
side2 = float(input("Enter the length of side 2: "))
side3 = float(input("Enter the length of side 3: "))
print("Perimeter:", triangle_perimeter(side1, side2,
side3))
else:
print("Invalid choice. Please enter a no. b/w 1 & 4.")

main()

34
O/p

35
19.Wap to roll 2 dices simultaneously, if the digits are same on both the
dices then declare the user as winner.

import random

def roll_dice():
return random.randint(1, 6)

def main():
print("Welcome to the Dice Rolling Game!")

while True:
input("Press Enter to roll two dice...")
result1 = roll_dice()
result2 = roll_dice()

print("You rolled dice 1:", result1)


print("You rolled dice 2:", result2)

if result1 == result2:
print("Congratulations! You are the winner!")
else:
print("Better luck next time!")

play_again = input("Do you want to roll again? (yes or


y/no or n): ").lower()
if play_again != 'yes' and play_again != 'y':
print("Thanks for playing! Goodbye.")
break

main()

36
O/p

37
20. WAP to Check if a list is a palindrome (reads the same forward and
backward).

def is_palindrome():
input_list = []
n = int(input('Enter the no of elements: '))

for i in range(n):
num = int(input('Enter a no.: '))
input_list.append(num)

reversed_list = list(reversed(input_list))

if input_list == reversed_list:
print('The entered sequence is a palindrome.')
else:
print('The entered sequence is not a palindrome.')

is_palindrome()

O/p

38
○THANK○
○YOU○

39

You might also like