Python Practical
Python Practical
program:
Output:
2. Write a python program to check whether the given number is even or
odd
Program:
#input value
num = int(input("enter the number:"))
#comparison
if num % 2 == 0:
print(num,"is even")
else :
print(num,"is odd")
Output:
3.1 To Implement Python Programs for Looping and control structure.
Program:
Output:
3.2 To Implement Python Programs for control structure.
Program:
#initialise counter
counter = 0
#loop for counter
while counter < 5:
print("count=",counter)
#increase counter
counter= counter+1
Output:
4.1 Write a python program to find following pattern
1) Left Triangle Star Pattern In Python
*
**
***
****
*****
Program :
#initialise i
i=0
#loop for pattern
while i<=5:
print(i*'*')
#i increment
i+=1
Output:
4.2 Write a python program to find following pattern
1) Left Triangle Star Pattern In Python
*
**
***
****
*****
Program :
rows = 5
k = 2 * rows - 2
for i in range(0, rows):
# process each column
for j in range(0, k):
# print space in pyramid
print(end=" ")
k=k-2
for j in range(0, i + 1):
# display star
print("* ", end="")
print("")
Output:
1. Write a python program to find the length of a given string and reverse
the same.
Program:
#define reverse
def reverse(string):
#start from back side
string = string[::-1]
return string
s = input("enter the string:")
#original string
print("before reverse string:",s)
#reverse string
print("after reverse string:",revers(s))
Output:
2. Write a python program to check whether the string is in
uppercase,lowercase and capitalise first
letter or not
Program :
#input string
s = input("enter the string:")
#check the string is in upper case or not
if s.isupper():
print("string is in upper case")
else:
print("string is in lower case")
#check the first letter is in capital or not
if s[0].isupper():
print("the first letter is capital")
else:
print("the first letter is not capital")
Output: