0% found this document useful (0 votes)
21 views4 pages

Week 1

Uploaded by

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

Week 1

Uploaded by

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

PYTHON PROGRAMMING (SKILL ENHANCEMENT COURSE)

SAMPLE EXPERIMENTS:

1. Write a program to find the largest element among three numbers.

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:

2. Write a program to display all prime numbers in interval.

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:

3. Write a program to swap two numbers without using a temporary variable.

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:

4. Demonstrate the following operators in python with suitable examples.


i. Arithmetic Operators v. Bit Wise Operators
ii. Relational Operators vi. Ternary Operator
iii. Assignment Operators vii. Membership Operators
iv. Logical Operators viii. Identity Operators

Aim: To write a program demonstrating various operators in python.

Code: //Arithmetic Operator//


a,b=2,3
c=a+b
print("a+b is",c)
d=a-b
print("a-b is",d)
e=a*b
print("a*b is",e)
f=a/b
print("a/b is",f)
g=a%b
print("a%b is",g)
Output:

Code: //Relational Operator//


a,b=10,7
c=a>b
d=a<b
e=a==b
f=a!=b
print("relational operator values are",c,d,e,f)

Output:

Code: //Assignment Operator//


a,b=10,7
print(a)
a=b
print(a)

Output:

Code: //Logical Operator//


a,b=True,False
PREPARED BY: n.v.nEERAJA, ASST. PROF., DEPT. OF CSE, MTIET 22
PYTHON PROGRAMMING (SKILL ENHANCEMENT COURSE)
c=a and b
print(c)
d=a or b
print(d)
e= not b
print(e)

Output:

Code: //Bit wise Operator//


a,b=10,4
c=a&b
d=a|b
e=a^b
f=~a
g=a>>2
h=a<<2
print(c,d,e,f,g,h)

Output:

Code: // Ternary Operator//


n=5
res = "Even" if n % 2 == 0 else "Odd"
print(res)

Output:

Code: // Membership Operator//


x = ["apple", "banana"]
print("banana" in x)
print("banana" not in x)

Output:

Code: // Identity Operator//


x = ["apple", "banana"]
y = ["apple", "banana"]
z=x
print(x is z)
print(x is not z)

Output:

5. Write a program to add and multiply complex numbers.

PREPARED BY: n.v.nEERAJA, ASST. PROF., DEPT. OF CSE, MTIET 23


PYTHON PROGRAMMING (SKILL ENHANCEMENT COURSE)
Aim: To write a program for adding and multiplying complex numbers in python.

Code:
a=2+4j
b=4+3j
c=a+b
print(c)

Output:

6. Write a program to print multiplication table of a given number.

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:

PREPARED BY: n.v.nEERAJA, ASST. PROF., DEPT. OF CSE, MTIET 24

You might also like