Q. Evaluate the following expression (stepwise) on paper first. Then execute it in Python shell. Compare your result with Python's. State reasons; find out the final output and its type.


1. len ('twenty four') / (len ('twenty') + 2 * (-1) ** 3)

Your Evaluation :-
11 / (6 + (-2))
11/4
2.75

Reason :- Precedence of parentheses bracket is greater than arithmetic operator.  

Output :- 2.75

Output's data type :- Float type.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> len ('twenty four') / (len ('twenty') + 2 * (-1) ** 3)
2.75


2. 3 < 10 or 5

Your Evaluation :-
3 < 10 or 5
True or 5
True

Reason :- Precedence of angle bracket is greater than Boolean ‘or’.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 3 < 10 or 5
True


3. 3 < (10 or 2)

Your Evaluation :-
3 < (10 or 2)
3 < 10
True

Reason :- Precedence of parentheses bracket is greater than angle bracket.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 3 < (10 or 2)
True


4. 3 < (2 or 10)

Your Evaluation :-
3 < (2 or 10)
3 < 2
False

Reason :- Precedence of parentheses bracket is greater than angle bracket.

Output :- False

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 3 < (2 or 10)
False


5. (10 < 100) or (50 < 100/0)

Your Evaluation :-
(10 < 100) or (50 < 100/0)
True or Error (ZeroDivisionError)
True

Reason :- ‘or’ operator ignore error because one value is true so ‘or’ operator not check further.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> (10 < 100) or (50 < 100/0)
True


6. (50 < 100/0) or (10 < 100)

Your Evaluation :-
(50 < 100/0) or (10 < 100)
Error or (10 < 100)
Error

Reason :- First operand is giving error so ‘or’ operator not check further.

Output :- ZeroDivisionError: division by zero

Output's data type :- Error

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>>  (50 < 100/0) or (10 < 100)
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    (50 < 100/0) or (10 < 100)
ZeroDivisionError: division by zero


7. 3 < 10 and 5

Your Evaluation :-
3 < 10 and 5
True and 5
5

Reason :- When first operand is true then ‘and’ operator check second operand which is true in this case. 

Output :- 5

Output's data type :- int that is integer.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> type (3 < 10 and 5)
<class 'int'>


8. 3 < (10 and 2)

Your Evaluation :-
3 < (10 and 2)
3 < (2)
False

Reason :- Precedence of parentheses bracket is greater than angle bracket.

Output :- False

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 3 < (10 and 2)
False


9. 3 < (2 and 10)

Your Evaluation :-
3 < (2 and 10)
3 < (10)
True

Reason :- Precedence of parentheses bracket is greater than angle bracket.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 3 < (2 and 10)
True


10. (10 < 100) and (50 < 100/0)

Your Evaluation :-
(10 < 100) and (50 < 100/0)
(True) and (50 < Error (division by zero))
(True) and (Error)
Error

Reason :- When first operand is true then ‘and’ operator check second operand which is giving error in this case. 

Output :- ZeroDivisionError: division by zero

Output's data type :- Error

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> (10 < 100) and (50 < 100/0)
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    (10 < 100) and (50 < 100/0)
ZeroDivisionError: division by zero


11. (50 < 100/0) and (10 < 100)

Your Evaluation :-
(50 < 100/0) and (10 < 100)
(50 < Error) and (10 < 100)
Error

Reason :- When first operand is giving error than ‘and’ operator will not check further.

Output :- ZeroDivisionError: division by zero

Output's data type :- Error

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> (50 < 100/0) and (10 < 100)
Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    (50 < 100/0) and (10 < 100)
ZeroDivisionError: division by zero


12. len("hello") == 25/5 or 20/10

Your Evaluation :-
len("hello") == 25/5 or 20/10
5 == 5 or 20/10
True or 2
True

Reason :- ‘or’ operator ignore error because one value is true so ‘or’ operator not check further.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> len("hello") == 25/5 or 20/10
True


13. -4 * -2 ** 3 + len (str (6))

Your Evaluation :-
-4 * -2 ** 3 + len (str (6))
-4 * -8 + len (str (6))
32 + len (str (6))
32 + len (‘6’)
32 + 1
33

Reason :- We should know the precedence order of operators.

Output :- 33

Output's data type :- int that is integer.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> -4 * -2 ** 3 + len (str (6))
33


14. 2 * (2 * (2 * len ("01")))

Your Evaluation :-
2 * (2 * (2 * len ("01")))
2 * (2 * (2 * 2))
2 * (2 * 4)
2 * 8
16

Reason :- Precedence of parentheses bracket greater than all other operator in python.  

Output :- 16

Output's data type :- int that is integer

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 2 * (2 * (2 * len ("01")))
16


15. str ((5 < 10) and (10 < 5) or (3 < 18) and not 8 < 18)

Your Evaluation :-
str ((5 < 10) and (10 < 5) or (3 < 18) and not 8 < 18)
str ((True) and (False) or (True) and False)
str ((False) or (False))
str (False)
‘False’

Reason :- Precedence of ‘and’ operator is greater than ‘or’ operator in python.

Output :- 'False'

Output's data type :- str that is string type.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> str ((5 < 10) and (10 < 5) or (3 < 18) and not 8 < 18)
'False'


16. Set values of variables C and D as "39" and 39 respectively.
Set value of variable E as D == C.
Now print the type of variables D, C, E.
Change the type of D such that E becomes True (use Type Casting)

Your Evaluation :-
Program:-

C = "39"
D = 39
E = C == D
print (type(D))
print (type(C))
print (type(E))

E = C == str (D)
print (E)

Reason :- Follow according to question says.

Output :-
<class 'int'>
<class 'str'>
<class 'bool'>
True

Output's data type :- bool.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

<class 'int'>
<class 'str'>
<class 'bool'>
True
>>> 


17. Set variables V1 = 42, V2 as 42.0, V3 = 42, V4 = 42.0
Set variables V5 as V1 == V2 and V6 as V1 is V2
V7 as V1 == V3 and V8 as V1 is V3
V9 as V2 == V4 and V10 as V2 is V4
Now state reasons for the values of V5, V6, V7, V8, V9, V10.
Are V9 and V10 same or different? Why?

Your Evaluation :-
According to question :-

V1 = 42
V2 = 42.0
V3 = 42
V4 = 42.0
V5 = V1 == V2
V6 = V1 is V2
V7 = V1 == V3
V8 = V1 is V3
V9 = V2 == V4
V10 = V2 is V4

Reason :- We should know about memory address of obect.

Output :-
>>> V5
True
>>> V6
False
>>> V7
True
>>> V8
True
>>> V9
True
>>> V10
True

Output's data type :- bool

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> V5
True
>>> V6
False
>>> V7
True
>>> V8
True
>>> V9
True
>>> V10
True
>>> V9 is V10
True

* Yes, V9 and V10 are same because both have same value that is True.


18. 5 < 20 and not 5 < * 20

Your Evaluation :-
5 < 20 and not 5 < * 20
True and not Error (invalid syntax)
Error

Reason :- When first operand is true then ‘and’ operator check second operand which is giving error in this case.

Output :-
SyntaxError: invalid syntax

Output's data type :- Error.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 5 < 20 and not 5 < * 20
SyntaxError: invalid syntax


19. "str (2 ** 4 ** 2)"

Your Evaluation :-
"str (2 ** 4 ** 2)"

Reason :- Python tret this as string because this statement is in under inverted.

Output :- "str (2 ** 4 ** 2)"

Output's data type :- str that is string.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> "str (2 ** 4 ** 2)"
'str (2 ** 4 ** 2)'


20. (len ('expression') / 10 + 15) / len (str (10 + 15))

Your Evaluation :-
(len ('expression') / 10 + 15) / len (str (10 + 15))
(10 / 10 + 15) / len (str (10 + 15))
(1 + 15) / len (str (10 + 15))
16 / len (str (10 + 15))
16 / len (str (25))
16 / len ('25')
16 / 2
8.0

Reason :- We have to know the precedence order of operators.

Output :- 8.0

Output's data type :- Float that is decimal form.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> (len ('expression') / 10 + 15) / len (str (10 + 15))
8.0


21. int (10.78) / 3 < len ("10.78")

Your Evaluation :-
int (10.78) / 3 < len ("10.78")
10 / 3 < len ("10.78")
3.3333333333333335 < 4
True

Reason :- We have to know the precedence order of operators.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> int (10.78) / 3 < len ("10.78")
True


22. len (str (25.00))

Your Evaluation :-
len (str (25.00))
len ('25.0')
4

Reason :- Python neglect double zero in decimal number.  

Output :- 4

Output's data type :- int that is integer.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> len (str (25.00))
4


23. bool (4 - len ('four'))

Your Evaluation :-
bool (4 - len ('four'))
bool (4 - 4)
bool (0)
False

Reason :- If we pass zero in bool () function then return False otherwise return True in all other case.

Output :- False

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> bool (4 - len ('four'))
False


24. bool (1 ** 10)

Your Evaluation :-
bool (1 ** 10)
bool (1)
True

Reason :- If we pass zero in bool () function then return False otherwise return True in all other case.

Output :- True

Output's data type :- bool that is Boolean.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> bool (1 ** 10)
True


25. (2 ** 3 ** 2 + 10) * 0

Your Evaluation :-
(2 ** 3 ** 2 + 10) * 0
(2 ** 9 + 10) * 0
(512 + 10) * 0
(522) * 0
0

Reason :- We have to know the precedence order of operators.

Output :- 0

Output's data type :- int is that integer.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> (2 ** 3 ** 2 + 10) * 0
0


26. 2 / int (1.5) + 200

Your Evaluation :-
2 / int (1.5) + 200
2 / 1 + 200
2 + 200
202

Reason :- Precedence of / operator is greater than + operator.

Output :- 202.0

Output's data type :- float that is Decimal number.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 2 / int (1.5) + 200
202.0


27. 10 ** 350

Your Evaluation :-
10 ** 350
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Reason :- Simply solved the equation.

Output :- 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Output's data type :- int that is integer.

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 10 ** 350
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


28. 10.0 ** 350

Your Evaluation :-
10.0 ** 350
Error (OverflowError)

Reason :- Answer is too large according to python.

Output :- Error (OverflowError)

Output's data type :- Error

Python's result (Paste the screenshot of expression's evaluation by Python's shell) :-

>>> 10.0 ** 350
Traceback (most recent call last):
  File "<pyshell#37>", line 1, in <module>
    10.0 ** 350
OverflowError: (34, 'Result too large')

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Kya flow of control ka practical solution mil skta h class 11

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post