Week 1
Week 1
SAMPLE EXPERIMENTS:
Aim: To write a program to find largest among three numbers using python.
Code:
a=2
b=4
c=3
if(a>=b) and (a>=c):
largest=a
elif (b>=a) and (b>=c):
largest=b
else:
largest=c
print("among the given three largest number is",largest)
Output:
Aim: To write a program for displaying all prime numbers within specified bound.
Code:
low, high = 2, 10
primes = [2]
for num in range(low, high + 1):
flag = 0
if num < 2:
flag = 1
if num % 2 == 0:
continue
iter = 2
while iter < int(num / 2):
if num % iter == 0:
flag = 1
break
iter += 1
if flag == 0:
primes.append(num)
print(primes)
Output:
Aim: To write a program to swap two numbers without using temporary variable in python.
Code:
x, y = 5, 7
print("Before swapping:", x, y)
x, y = y, x
print(“after swapping:”,x,y)
PREPARED BY: n.v.nEERAJA, ASST. PROF., DEPT. OF CSE, MTIET 21
PYTHON PROGRAMMING (SKILL ENHANCEMENT COURSE)
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Code:
a=2+4j
b=4+3j
c=a+b
print(c)
Output:
Aim: To write a program for adding and multiplying complex numbers in python.
Code:
number=9
for i in range(1, 11):
print(number, "x", i, "=", number*i)
Output: