K L University Department of Ece Computer Networks Lab Manual (15Cs2208) Python Basic Programs
K L University Department of Ece Computer Networks Lab Manual (15Cs2208) Python Basic Programs
DEPARTMENT OF ECE
COMPUTER NETWORKS LAB MANUAL (15CS2208)
Python Basic Programs:
1.Write a python program to print the Welcome message
print(‘Welcome to CN Lab’)
a=15
b=10
print(a+b)
a=5
b,c=2.0,"CN"
print(a)
print(b)
print(c)
print(d)
str="welcome to CN Lab"
print(str)
print(str[0])
print(str[3:7])
print(str[11:])
print(str+" Manual")
a=int(input('Enter a value:'))
b=int(input('Enter b value:'))
c=int(input('Enter c value:'))
print('a is maximum')
elif(b>c):
print('b is maximum')
else:
print('c is maximum')
or
print(max(a,b,c))
6.Write a python program to find out the given number is prime or not
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
else:
factorial = 1
if num < 0:
elif num == 0:
else:
factorial = factorial*i
8.Write a python program to print the prime numbers in the given range
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num)
n1 = 0
n2 = 1
count = 2
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
print(n1)
print(n2)
nth = n1 + n2
print(nth)
n1 = n2
n2 = nth
count += 1
X = [[12,7],
[4 ,5],
[3 ,8]]
result = [[0,0,0],
[0,0,0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[j][i] = X[i][j]
for r in result:
print(r)
words = my_str.split()
words.sort()
print(word)
vowels = 'aeiou'
ip_str = ip_str.casefold()
count = {}.fromkeys(vowels,0)
if char in count:
count[char] += 1
print(count)