Operators Assignment
Q 1
The Output of a = 2+3-4/2**2 and also tell its type?
4 and int
4.0 and float
1.0 and float
5 and int
sol 1
a= 2+3-4/2**2
print(a)
print(type(a))
Option B is correct.
Q 2.
The output of the following python code snippet
print(type(4/2))
print(type(4//2))
float and float
float and int
int and float
int and int
Sol of Q 2.
print(type(4/2))
print(type(4//2))
Ans: (B)
Q 3.
What will be the output of the following python code snippet
a= 12
print(type(a))
a=’12345’
print(type(a))
a. Int and str
b. Int and int
c. str and int
d. str and str
Sol of Q. 3
a=12
print(type(a))
a="12345"
print(type(a))
Ans: a
Q 4.
In which manner are operators with the same precedence evaluated?
a. Left to right
b. Right to left
c. Can’t say
d. None of the Above Mentioned
Ans: (a)
Q. 5
Output of a = 2*3/4**1==2.00
a. 1.5
b. 2
c. True
d. False
Sol Of Q. 5
a=2*3/4**1==2.00
print(a)
Ans: False
Q. 6
Output of the following
print(100>2 and 100 > 30)
a. True
b. False
c. 100
d. 30
Sol of Q. 6
print(100>2 and 100>3)
Ans: a
Q. 7
What will be the output of the following code
print(True or True and False)
a. True
b. False
Sol of Q. &
print(100>2 and 100>3)
Answer :
Q. 8
What will be the precedence of
a. Not
b. And
c. Or
a. Abc
b. Bac
c. Bca
d. Cab
Answer: a (Not, And, or)
Q. 9
The Output of the following 2/2*3**2<=10
a. True
b. False
c. 9
d. 10
Sol of Q. no. 9
print(2/2*3**2<=10)
Ans: A (True)
Q no. 10
type(22%3) = ?
a. Int
b. Str
c. Float
d. Can’t say
Sol Of Q. 10
print(type(22%3))
Answer : (a) the answer will be in int.
Q NO 11:
Which will give an error?
a. A++
b. ++a
c. A += 1
d. Both A and B
Answer: (d)
Q No. 12:
Suppose, there are 5 rupees in your pocket.
I am giving you 17 Rs. How many rupees do you have now?
Now I am giving you 39 Rs. How many rupees do you have now?
Now I am taking 23 Rs. back. How many rupees do you have now?
Again I am giving you 932 Rs. How many rupees do you have now?
Sol of Q no 12:
amar=5
amar+=17
print(amar) #22
amar+=39
print(amar) #61
amar-=23
print(amar) #38
amar+=932
print(amar) #970
Q no 13:
Calculate the value of ( a ) in the expression: a =( 5 + 3 - 2 / 2 ).
Sol of Q no 13:
a=5+3-2/2
print(a) #7.0
Q no 14:
Calculate the value of ( b ) in the expression: b = ((8 - 2) * 3 / 2 )
Sol of Q no 14:
b=(8-2)*3/2
print(b) #9.0
Q no 15:
Calculate the value of ( c ) in the expression: c =( 10 / 2 + 3 * 4 )
Sol of Q no 15:
c=10/2+3*4
print(c) #17.00
Q no 16:
Calculate the value of ( d ) in the expression: d =( 7 + 3 * (2 ** 2) - 5 )
Sol of Q no 16:
d=7+3*(2**2)-5
print(d) #14
Q no 17:
Calculate the value of ( e ) in the expression: e =( (6 / 3) + (8 - 4) )
Sol of Q no 17:
e=(6/3)+(8-4)
print(e) #6.0
Q no 18:
Calculate the value of ( f ) in the expression: f = (5 * (3 + 2) - 8 / 4 )
Sol of Q no 18:
f=5*(3+2)-8/4
print(f) #23.0
Q no 19:
Calculate the value of ( g ) in the expression: g =( 12 / 4 + 7 - 3 * 2 )
Sol of Q no 19:
g=12/4+7-3*2
print(g) #4.0
Q no 20:
Calculate the value of ( h ) in the expression: h = (9 - 3 + 4 * (2 ** 2) )
Sol of Q no 20:
h=9-3+4*(2**2)
print(h) #22
Q no 21:
Suppose, you have 150 rupees.
You spend 45 rupees on a meal. How many rupees do you have now?
Then, you spend 32 rupees on a movie ticket. How many rupees do you have now?
Next, you spend 18 rupees on snacks. How many rupees do you have now?
Finally, you spend 25 rupees on transportation. How many rupees do you have now?
Sol of Q no 21:
amar=150
amar-=40
print(amar) #110 left
amar-=32
print(amar) #78 left
amar-=18
print(amar) #60 left
amar-=25
print(amar) #35 left
Q no 22:
You have 200 rupees.
You decide to buy a book for 60 rupees. How much do you have left?
Then, you receive 30 rupees from a friend. How much do you have now?
You decide to donate 10% of your current money to charity. How much do you have
left?
You find 5 rupees in your pocket. Add this to your current amount.
You want to split the remaining amount equally between yourself and a friend. How
much does each of you get?
You win a prize and the amount you have is tripled. How much do you have now?
Finally, you purchase a rose, usually the price of rose is 50 rupees but todaythe
price is incremented by 10 rupees due to demand. How much do you pay now?
Sol of Q no 22:
amar=200
#book cost 60 rs
amar-=60
print(amar) #140 left
#received 30 rs from friend.
amar+=30
print(amar) #Now the amount is 170
#10% to the charity
amar=left_after_charity=170*9/10
print(amar) #153 is left
#found 5 rs in pocket
amar+=5
print(amar) #total amount is 158
#spliting remaining amount in to 2 parts.
amar=spliting_in_two_parts=amar/2
print(amar) #79.0 rs left
amar=winning_triple_of_current_amount=amar*3
print(amar) #237.0 left
actual_price_of_rose=50*11/10
print(actual_price_of_rose) #55 rs.