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

Computer Practical

The document provides a series of Python programming exercises covering fundamentals, data types, flow control, strings, and collections. Each section includes example code, expected output, and instructions for tasks such as displaying names, calculating factorials, and manipulating lists. The exercises are designed to help users practice and understand basic programming concepts in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Computer Practical

The document provides a series of Python programming exercises covering fundamentals, data types, flow control, strings, and collections. Each section includes example code, expected output, and instructions for tasks such as displaying names, calculating factorials, and manipulating lists. The exercises are designed to help users practice and understand basic programming concepts in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

s Computer Practical

Python Fundamentals: (Print any 2)


01. Write a program to display your name on screen.
Name = input(“Enter your name: “)
Print(“My name is: “, name)

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

Data Types: (Print any 2)


03. Write a program to input x,y,z and calculate 4x⁴+3y³+9z+6π
Import math
import math

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

Flow of Control: (Print only 2)


05. Write a program to calculate the factorial of a number.

num = int(input("Enter the number: "))


fact = 1
for i in range(1,num+1):
fact = fact*i
print (“The factorial of the number is: ", fact)

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
************

Strings: (print any 2)


11. Write a program to input name and surname as two different strings, join them, and
print as a single string.
Name3=input(“Enter your name: “)
Surname3=input(“Enter your surname: “)
Print(name3+” “+surname3)

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)

print("The length is: ", length)

print("The first character is: “, string[@])


print("The last character is: “, string[-1])
print("The string in reverse is: ", string[::-1])

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy