80% found this document useful (5 votes)
15K views

Python 1-10 Practicals PDF

The document contains 10 programming practices involving basic Python concepts like printing, taking user input, performing calculations, conditional statements, loops and functions. The practices cover printing "Hello World", calculating sum and area, checking even/odd numbers, displaying numbers in loops, finding greatest of 3 numbers and swapping two variables. Output for each practice is included.

Uploaded by

palak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
80% found this document useful (5 votes)
15K views

Python 1-10 Practicals PDF

The document contains 10 programming practices involving basic Python concepts like printing, taking user input, performing calculations, conditional statements, loops and functions. The practices cover printing "Hello World", calculating sum and area, checking even/odd numbers, displaying numbers in loops, finding greatest of 3 numbers and swapping two variables. Output for each practice is included.

Uploaded by

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

Practical ​1​ : Print Hello World.

print​(​"hello world"​)

o​/​p​:
hello world

Practical ​2​ : To display the sum of two numbers.

x​ = ​int​(​input​(​'enter 1st number:'​))


y​ = ​int​(​input​(​'enter 2nd number:'​))
print​(​"sum :"​,​x​+​y​)

o​/​p​:
enter 1 ​ ​st​ n
​ umber​: 2​
enter 2 ​ ​nd n​ umber​: 3 ​
sum : 5 ​

Practical ​3​ : Calculate area of circle.

r = float(​input​(​'enter radius'​))
pi = ​3.14
print​(​"area :"​,pi*(r**​2​))

o​/​p​:
enter radius ​10
area : ​314.0

​ ​ : Accept a number from keyboard ​and​ test whether the given


Practical 4
number is even ​or​ odd.

x​ = ​int​(​input​(​'enter number'​))
if​(​x​%​2​ == ​0​):
​print​(​'number is even'​)
else​:
​print​(​'number is odd '​)

o​/​p​:
enter ​number​ ​6
number​ ​is​ even
Practical ​5​ : To display numbers from ​1​ to ​10​ using while loop.

i=​1
while​(i<=​10​):
​print​(i)
i+=​1

o​/​p​:
1
2
3
4
5
6
7
8
9
10

Practical ​6​ : To display even numbers between X ​and​ Y.

​ nt​(​input​(​'enter 1st number'​))


x​ = i
y​ = i​ nt​(​input​(​'enter 2nd number'​))
for​ i in ​range​(​x​,​y​+​1​):
​if​(i%​2​ == ​0​):
​print​(i)

o​/​p​:
enter 1 ​ ​st​ number1
enter 2 ​ ​nd number10
2
4
6
8
10

Practical ​7​ : To display the elements of a list using for loop.

​ nt​(​input​(​'enter 1st number'​))


x​ = i
y​ = i​ nt​(​input​(​'enter 2nd number'​))
for​ i in ​range​(​x​,​y​+​1​):
​print​(i)
o​/​p​:
enter 1 ​ ​st​ n
​ umber​ 4​ 1
enter 2 ​ ​nd n​ umber​ 4​ 5
41
42
43
44
45

Practical ​8​ : Draw following patterns using nested loops.

1​)n = ​int​(​input​(​"enter n:"​))


for​ i in ​range​(n):
​for​ ​j​ in ​range​(i+​1​):
​print​(​"*"​,end=​""​)
​print​()
​o​/​p​:
enter n:​3
*
**
***

2​)n = ​int​(​input​(​"enter n:"​))


for​ i in ​range​(​0​,n):
​for​ ​j​ in ​range​(​0​,i+​1​):
​print​(​j​+​1​,end=​""​)
​print​()
​o​/​p​:
enter n:​3
1
12
123

3​)n = ​int​(​input​(​"enter n:"​))


for​ i in ​range​(​0​,n):
​for​ ​j​ in ​range​(​0​ , n - i):
​print​(​" "​,end=​""​)
​for​ ​j​ in ​range​(​0​, i + ​1​):
​print​(​"* "​,end=​""​)
​print​()
​o​/​p​:
enter n:​3
*
* *
* * *

4​)n = ​int​(​input​(​"enter n:"​))


for​ i in ​range​(​0​,n):
​for​ ​j​ in ​range​(​0​ , n - i):
​print​(​" "​,end=​""​)
​for​ ​j​ in ​range​(​0​, i + ​1​):
​print​(i+​1​,end=​""​)
​print​()
​o​/​p​:
enter n:​3
​1
​22
​333

Practical ​9​ : Write a Python function ​to​ ​swap​ ​two​ ​numbers​.

x​ = ​int​(​input​(​'enter 1st number'​))


y​ = ​int​(​input​(​'enter 2nd number'​))
temp = ​x
x​ = ​y
y​ = temp
print​(​"swap value of x and y is:"​,​x​,​"and"​,​y​)

o​/​p​:
enter ​1​st​ number3
enter ​2​nd number4
swap value of ​x​ ​and​ ​y​ i​s:​ ​4​ ​and​ ​3

Practical ​10​ : Write a Python function ​to​ ​find​ ​the​ ​greatest​ ​of​ 3 ​numbers​.

x​ = ​int​(​input​(​'enter 1st number'​))


y​ = ​int​(​input​(​'enter 2nd number'​))
z​ = ​int​(​input​(​'enter 3rd number'​))
if​ (​x​>=​y​ ​and​ ​y​>=​z​):
​print​(​'max value is:'​,​x​)
elif (​y​>=​x​ ​and​ ​x​>=​z​):
​print​(​'max value is:'​,​y​)
else​:
​print​(​'max value is:'​,​z​)

o​/​p​:
enter ​1​st​ number3
enter ​2​nd number4
enter ​3​rd number5
max​ value i​s:​ ​5

You might also like