Python Assignment 1
Q1.
Consider:
x=20
y=13
z=2
p=0.5
q=12.79
i=13
j=29.0
k=y-11
a=''
b=' '
c='python'
d='Python'
e='PYTHON'
f='Python'
g='PYTHON'
h='python'
l=(3+4.6j)
m=(3+4.5j)
r=0
s=0.0
A. Find:
1. x/y
2. x//4
3. y-i+p
4. y**z
5. y%z
6. q%p
7. y+j%4
8. y/x*z
B. Find:
1. y>p*26
2. (y>p)*26
3. x<=y<x+y
4. x//y<p*20
5. X!=y*z+3
6. x-(3!=y)*2
7. X==y*z+3
C. Find:
1. print(y is i)
2. print(g==e)
3. print(e is not g)
4. print(k==z)
5. print(z is not k)
6. print(l is m)
7. print(x>y and y>z)
8. print(x>y or y>z)
9. print(not x>y or y>z)
[Link](x-y*2>y*2 and y*p>y)
[Link](not(x-y*2>y*2 and y*p>y))
[Link](x-y*2>y*2 or not y*p>y)
[Link](not x-y*2>y*2 and y*p>y)
[Link](p or r)
[Link](q and p)
[Link](not q or p)
[Link](a and not q)
[Link](z+2 or s)
[Link](d or f)
[Link](c==h and e==g)
[Link](g or a)
[Link](~(int(j)))
[Link](~55)
[Link](len("python")==25/5 or 20/10)
[Link](3<5 or 50/(5-(3+2)))
[Link](2*(2*(len("01"))))
[Link](50/(5-(3+2))or 3<5)
Q2. What will be the output of following expression?
(5<10) and (10<5) or (3<18) and not 8<18
Q3. Write the following expressions in Python:
a) 1/3b2h
b) an * am or an+m
Q4. Find the errors:
a) a=bool(0)
b=bool(1)
print(a==false)
print(b==true)
b) print(“hello”+2)
print(“hello”*2)
print(“hello”/2)
Q5. Evaluate the following expressions:
a) 5 % 10 + 10 < 50 and 29 >= 29
b) 7 ** 2 // 4 + 5 > 8 or 5 != 6
c) 7 /4 < 6 and ‘I am fine’ > ‘I am not fine’
d) 10 + 6 * 2 ** 2 != 9 // 4 – 3 and 29 >= 29 / 9
e) -15 | 22
f) ~ -20
g) 15 ^ 22
h) 8<<3
i) 40>>3
j) ~ 22
k) 17 & 22
Q6. Find output of:
a. x,y=2,6
x,y=y,x+2
print(x,y)
b. x,y=7,2
x,y,x=x+1,y+3,x+10
print(x,y)
c. x,y=20,60
y,x,y=x,y-10,x+10
print(x,y)
Q7. Give the output of following:
(a)
a=0
b=5
x=(a&b)|(a&a)|(a|b)
print("x")