0% found this document useful (0 votes)
70 views20 pages

Print (1) X 2 Print (X) Output

The document contains code snippets and output from a Python practical session. It includes examples of printing, variables, operators, strings, lists, conditional statements, loops, functions, and more. Various outputs are displayed after each code block to demonstrate the results. The document contains over 40 code examples with explanations and outputs, covering fundamental and intermediate Python concepts.

Uploaded by

Kidrah 2.0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views20 pages

Print (1) X 2 Print (X) Output

The document contains code snippets and output from a Python practical session. It includes examples of printing, variables, operators, strings, lists, conditional statements, loops, functions, and more. Various outputs are displayed after each code block to demonstrate the results. The document contains over 40 code examples with explanations and outputs, covering fundamental and intermediate Python concepts.

Uploaded by

Kidrah 2.0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

PYTHON PRACTICAL Name: - Hardik R.

kangane
Roll no.: - 436

print(1)
x=2
print(x)
output: -

total=1+\
2+\
3
print(total)
output: -

a,b,c=1,2,"hey"
print(c)
print(b)
output: -

str="hey"+"hi"
print(str)
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
str="haha"*2
print(str)
output: -

str = 'Hello world!'


print(str)
print(str[0])
print(str[2:5])
print(str[2:])
print(str * 2)
print(str + "test")
print(str[::-1])

output: -

a="Hi life"
print(a)
print(len(a))
print(len("i am"))
print(a[0])
print(a[4])
print(a[-1])#reverse indexing
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
b="abcdefghijk"
print(b[2:5])
print(b[2:])
print(b[:5])
print(b[7:9])

output: -

num=5
if(num<10):
print("number is smaller than 10")

print("this statement will always be executed")

output: -

a=7
b=0
if(a>b):
print("a is greater than b")
else:
print("b is grater than a")
output: -

if('python' in['java','python','c#']):
print("true")

output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436

a=7
b=8
if(a>b):
print("a is greater than b")
else:
print("b is grater than a")

output: -

passing_score=60
my_score=147
if(my_score>=passing_score):
print("congratulation!!!")
print("you are pass in exam")
else:
print("sorry!!")
print("you are faild")

output: -

num=10
if(num==0):
print("number is zero")
elif(num>5):
print("number is grater than 5")
else:
print("number is smaller than 5")
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
if('python' in['java','python','c#']):
print("python is present in the list")
if('java' in['java','python','c#']):
print("java is present in the list")
if ('c#' in ['java', 'python', 'c#']):
print("c# is present in the list")
output: -

my_marks=60
if(my_marks<35):
print("sorry!!! you are fail in exam")
elif(my_marks>=35 and my_marks<60):
print("you passed!!!")
elif(my_marks>=60 and my_marks<85):
print("passed in first class")
else:
print("passed in first class with distinction")
output: -

a=int(input("enter a="))
b=int(input("enter b="))
c=a+b
print("addition=",c)
d=a-b
print("substraction=",d)
e=a*b
print("multiplication=",e)
f=a/b
print("division=",f)
g=a%b
print("modolus=",g)
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
s1="SY"
s2="IT"
print(s1+s2)

a=int(input("enter a="))
b=int(input("enter b="))
c=int(input("enter c="))

if(a>b and a>c):


print("a is grater")
elif(b>a and b>c):
print("b is grater")
else:
print("c is grater")

output: -

a=int(input("enter number="))
if(a>0):
print("number is +ve")
else:
print("number is -ve")

a=int(input("number ="))
if(a%2==0):
print("no. is Even")
else:
print("no. is Odd")

output: -

num=(int(input("enter the number =")))


rev=0
while num>0:
remainder=num % 10
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
rev=(rev * 10) + remainder
num=num // 10

print(rev)

output: -

num=(int(input("enter the number =")))


rev=0
pali=num
while num>0:
remainder=num % 10
rev=(rev * 10) + remainder
num=num // 10

print(rev)
if(rev==pali):
print("number is PALINDROM!!!")
else:
print("number is NOT PALINDROM!!!")
output: -

num = 7
if (num < 0): print("number is smaller than zero")
elif(num > 0): print("number is grater than zero")
else: print("number is zero")
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
num1 = 10
num2 = 20
num3 = 30
if (num1 == 10 and num2 == 20 and num3 == 30):
print("all the conditions are true")
output: -

str = "python"
for i in str:
print(i)
output: -

list = [1,2,3,4,5,6,7,8,9,10]
n=5
for i in list:
c = n*i
print(c)
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
list = [10,30,23,43,65,12]
sum = 0
for i in list:
sum=sum + i
print("the sum is :",sum)
output: -

for i in range(10):
print(i)
output: -

n = int(input("enter the number:"))


for i in range(1,11):
c = n*i
print(n,"*",i,"=",c)
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
n = int(input("enter the number:"))
for i in range (2,n,2):
print(i)
output: -

list = ['sameer','arjun','dyano','shekhar']
for i in range(len(list)):
print("hello",list[i])
output: -

rows = int(input("enter the number:"))


for i in range(1,rows+1):
for j in range(i):
print("*",end= '')
print()
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
i=1
while (i<=10):
print(i)
i=i+1
output: -

i=1
number = int(input("enter the number:"))
while (i<=10):
print("%d X %d = %d\n"%(number,i,number*i))
i=i+1
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
nterm = int(input("how many term?"))
n1, n2 = 0, 1
count = 0
if nterm <=0:
print("please enter +ve number")
else:
print("fibonaccai sequance upto",nterm)
while count < nterm:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count=count+1
output: -

for letter in 'python':


if letter == 'h':
break
print("current letter:",letter)

output: -

var = 10
while var > 0:
print("current variable value:",var)
var = var - 1
if var == 5:
break
print("good bye!!!")
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
output: -

for letter in 'python':


if letter == 'h':
continue
print("current letter:",letter)
output: -

var = 10
while var > 0:
var = var - 1
if var == 5:
continue
print("current variable value:",var)
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
n = int(input("enter a three digit number:"))
sum = 0
temp = n
while temp > 0:
dig = temp % 10
sum = sum + dig ** 3
temp = temp // 10

if n == sum:
print(n,"Armstrong no.")
else:
print(n,"not Armstrong no.")
output: -

import math
n = int(input("enter a number:"))
a = math.sqrt(n)
print(a)
print(math.log(a))
print(math.exp(a))
print(abs(-14))
output: -

name = input("enter your name :")


print("your name is :\n"+ name)

age = int(input("enter your age:"))


year = str ((2021-age)+100)
print(name +"will be 100 yrea old in year "+ year)
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
output: -

name = input("enter your name :")


print("your name is :\n"+ name)

age = int(input("enter your age:"))


year = str ((2021-age)+100)
print(name +"will be 100 yrea old in year "+ year)

output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436

PRACTICAL NO. 2
def count():
list = ['a','e','i','o','u']
x = 's'
if x in list:
return True
else:
return False

a = count()
print(a)
def func():
list1 = ['a','e','i','o','u']
c=0
for i in list1:
c=c+1
print(c)
return
func()
output: -

a = [2,3,4]
for x in a:
for i in range(1,x+1):
print("*",end="")
print("")
output: -

a = [2,3,4]
for x in a:
for i in range(1,x+1):
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
print("*",end="")
print("")
output: -

rows = int(input("enter the number"))


for i in range(1,rows+1):
for j in range(i):
print(i,end="")
print()
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
PRACTICAL NO. 3
(some program is remain here)
l = [1,3,8,2,11,20,7]
for x in l:
if x<5:
print(x)

output: -

def func():
l = [1,2,3,4,5,6,7]
l2 = [2,4,6,8]
for x in l:
for y in l2:
if x==y:
return True
a=func()
print(a)
output: -

def changeme(mylist):
mylist.append([1,2,3,4])
print("value inside the function:",mylist)
return

mylist = [10,20,30];
changeme( mylist);
print("value outside the function:",mylist)
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436

def changeme(mylist):
mylist = [1,2,3,4]
print("vlaue inside the function:",mylist)
return
mylist = [10,20,30]
changeme( mylist)
print("value outside the function:",mylist)
output: -

def printme(str):
print(str)
return
printme(str)

def printme(str):
print(str)
return;
printme( str = "My string")

def printinfo(name ,age):


print("name :",name)
print("Age:",age)
return
printinfo(age= 50, name="miki")

def printinfo( name, age = 35):


print("name:",name)
print("age:",age)
return;
printinfo( age=50, name="miki");
printinfo(name="miki");
output: -
PYTHON PRACTICAL Name: - Hardik R. kangane
Roll no.: - 436
def printinfo(arg1 , *vartuple):
print("output is:")
print(arg1)
for var in vartuple:
print(var)
return;
printinfo(10);
printinfo(70,60,50);
output: -

You might also like