Computer Practical
Computer Practical
Output:-
Enter your name: Priyansh Nagar
My name is: Priyansh Nagar
02. Write a program to display name, class and section separated by ‘-‘.
Name1 = input(“Enter your name: “)
Class1 = input(“Enter your class: “)
Section1 = input(“Enter your section: “)
Print(name1,class1,section1,sep=”-“)
Output:-
Enter your name: Priyansh Nagar
Enter your class: 11
Enter your section: A
Priyansh Nagar-11-1
x = int(input("Enter x: "))
y = int(input("Enter y: "))
z = int(input("Enter z: "))
print(“The value of 4x^4+3y^3+9z+6pi is: “,
math.pow((4*x),4)+math.pow((3*y),3)+9*z+6*math.pi)
Output:-
Enter x: 2
Enter y: 3
Enter z: 5
Vlue of 4x^4+3y^3+9z+6pi is: 208.84955592153875
Output:-
The factorial of number is: 120
06. Write a program to input your name and surname separately, join them and print in the
following manner:
************
name surname
************
name2 = input(“Enter your name: ")
surname2 = input("Enter your surname:
X = name2+" "+surname2
length = len(x)
for i in range(1,length+1):
print("*",end="")
print()
print (x)
for i in range(1,length+1):
print("*",end="")
Output:-
Enter your name: Priyansh
Enter your surname: Nagar
************
Priyansh Nagar
************
Output:-
Enter your name: Priyansh
Enter your surname: Nagar
Priyansh Nagar
12. Write a program to input a string, find its length, first character, last character and
print it in reverse.
string = input( Enter the string:
length = len(string)
Output:-
The length is: 22
The first character is: H
The last character is: 1
The string in reverse is: lieN@ si eman ym olleH
Lists/Tuple/Dictionary
16. Write a program to make a list containing 5 numbers, print them and multiply each
number by 5.
List1 = [1,2,3,4,5]
print (1listl)
for i in range(®,5):
list1[i] = list1[i]*5
print (list1)
Output:-
[1, 2, 3, 4,5]
[5, 10, 15, 20, 25]
17. Write a program to input 10 numbers in a string and calculate their sum and
average.
list2
sum1 = 0
for i in range(0,10):
num = int(input(“Enter the number: "))
list2.append (num)
sum1 = sum1+num
print("The sum of the numbers is: *, sum1)
print("The average of the numbers is: *, sum1/10)
Output:-
Enter the number: 1
Enter the number: 2
Enter the number: 3
Enter the number: 4
Enter the number: 5
Enter the number: 6
Enter the number: 7
Enter the number: 8
Enter the number: 9
Enter the number: 10
The sum of numbers is: 55
The average of the numbers is: 5.5
20. Write a program to enter a festival name and search whether the name present in
the tuple or not without using membership operator. Print appropriate message.
tuplel = ("Holi","Diwali”,"Christmas”,"Eid")
festival = input(“Enter the festival name: ")
flag = 0
for i in range(0,4):
if tuple1[i].lower() == festival:
flag = 1
break
if flag == 1:
print("The festival is present in the tuple.")
else:
print("The festival is not present in the tuple.")
Output:-
Enter the festival name: holi
The festival is present in tuple