0% found this document useful (0 votes)
99 views

Python Bridge Course

This document contains a Python bridge course assignment submitted by a student named Kartheek Panduru. It covers various Python operators like arithmetic, assignment, comparison, logical, bitwise, identity and membership operators. It also covers type conversion, control flow statements like if/else, for/while loops, and statements like break, continue and pass. The assignment contains examples and output for each concept explained.

Uploaded by

Praveen Panduru
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Python Bridge Course

This document contains a Python bridge course assignment submitted by a student named Kartheek Panduru. It covers various Python operators like arithmetic, assignment, comparison, logical, bitwise, identity and membership operators. It also covers type conversion, control flow statements like if/else, for/while loops, and statements like break, continue and pass. The assignment contains examples and output for each concept explained.

Uploaded by

Praveen Panduru
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Python Bridge Course

ASSIGNMENT - 1

Name: Kartheek Panduru


Section: B-10
Regd. No: 121910310016
Operators
1. Arithmetic operators
a,b=5,3
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a//b)
print(a%b)
Output:
8
2
15
1.6666666666666667
1
2

2. Assignment Operators
a=9
print(a)
a+=9
print(a)
a-=9
print(a)
a*=9
print(a)
Output:
9
18
9
81
3. Comparison Operators
a,b=2,3
print(a<b)
print(a>b)
print(a<=b)
print(a>=b)
print(a==b)
print(a!=b)
Output:
True
False
True
False
False
True
4. Logical Operators
a,b=3,2
print(a==3 and b<5)
print(a>3 and b<=1)
print(a!=3 and b<7)
print(a>1 and b==9)
print(a>5 or b!=2)
print(a<9 or b>1)
print(a!=3 or b==2)
print(a<5 or b>2)
print(not(a==3 or b==2))
print(not(a!=3 or b==5))
print(not(a==3 and b==5))
print(not(a!=3 and b==5))
Output:
True
False
False
False
False
True
True
True
False
True
True
True
5. Bitwise Operators
a,b=5,4
print(a&b)
print(a|b)
print(a^b)
print(a<<b)
print(a>>b)
Output:
4
5
1
80
0
6. Identity Operators
a=["Hello","World"]
b=["Python","World"]
print(a is b)
print(a is not b)
Output:
False
True
7. Membership Operators
a=["Hi","Hello","How","Are","You"]
b="Hello"
print(b in a)
print(b not in a)
Output:
True
False

Type conversion
1. Implicit conversion
a,b=20,30.5
c=a+b
print(type(a))
print(type(b))
print(c)
print(type(c))
Output:
<class 'int'>
<class 'float'>
50.5
<class 'float'>
2. Explicit conversion
a=20
b=float(a)
print(type(a))
print(b)
print(type(b))
Output:
<class 'int'>
20.0
<class 'float'>

Control flow statements


1. if statement
a=5
if a>0:
print(a, "is a positive number")
Output:
5 is a positive number
2. if…else statement
a=9
if a>=0:
print("positive")
else:
print("negative")
Output:
Positive
3. if…elif…else statement
a=3
if a>0:
print("positive")
elif a==0:
print("zero")
else:
print("negative")
Output:
Positive
4. nested if statement
a=-5
if a>=0:
if a>0:
print("positive")
else:
print("zero")
else:
print("negative")
Output:
Negative
5. for loop in range
a=0
for x in range(5,10):
print(x)
Output:
56789
# for loop for strings
words=["basketball","music","badminton","mobile","laptop"]
for x in words:
print(x)
Output:
basketball music badminton mobile laptop
6. while loop in range
a=0
while (a<5):
print(a)
a=a+1
Output:
01234
7. break statement
for i in range(10):
if(i==5):
break
print(i)
i=i+1
Output:
01234
8. continue statement
for i in range(1,11):
if(i==7):
continue
else:
print(i)
Output:
1 2 3 4 5 6 8 9 10
9. pass statement
a=["hi","hello","hola","hey"]
for i in a:
if(i=="hola"):
pass
else:
print(i)
Output:
hi hello hey
ASSIGNMENT - 2

Name: Kartheek Panduru


Section: B-10
Regd. No: 121910310016

You might also like