0% found this document useful (0 votes)
143 views3 pages

Float Assignment

The document discusses various operations that can be performed on float values in Python. It includes declaring and checking the type of a float, arithmetic operations, comparison operators, equality operators, logical operators, and membership operators applied to floats. The key points are: - Float values can be declared and stored in variables, and their type and id can be checked. - Arithmetic, comparison, equality, and logical operators can be used to perform calculations and comparisons on float values stored in variables. - Membership operators like 'in' and 'not in' can check if a float value is a member of a sequence, set, dictionary, or range, returning a boolean. - The ids of float values

Uploaded by

Aditya Mishra
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)
143 views3 pages

Float Assignment

The document discusses various operations that can be performed on float values in Python. It includes declaring and checking the type of a float, arithmetic operations, comparison operators, equality operators, logical operators, and membership operators applied to floats. The key points are: - Float values can be declared and stored in variables, and their type and id can be checked. - Arithmetic, comparison, equality, and logical operators can be used to perform calculations and comparisons on float values stored in variables. - Membership operators like 'in' and 'not in' can check if a float value is a member of a sequence, set, dictionary, or range, returning a boolean. - The ids of float values

Uploaded by

Aditya Mishra
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/ 3

Q. ​Declare a float value and store it in a variable.

Check the type and print the id of the same.

Q.​ ​Arithmetic Operations on float


Take two different float values.
Store them in two different variables.
Do below operations on them:-
​Find sum of both numbers
​Find difference between them
​Find the product of both numbers.
​Find value after dividing first num with second number
​Find the remainder after dividing first number with second number
​Find the quotient after dividing first number with second number
​Find the result of the first num to the power of the second number.

Q.​ Comparison Operators on float


Take two different float values.
Store them in two different variables.
Do below operations on them:-
Compare these two numbers with below operator:-
Greater than, '>'
Smaller than, '<'
Greater than or equal to, '>='
Less than or equal to, '<='
Observe their output(return type should be boolean)

Q.​ ​Equality Operator


Take two different float values.
Store them in two different variables.
Equate them using equality operators (==, !=)
Observe the output(return type should be boolean)

Q.​ Logical operators


Observe the output of below code
Cross check the output manually

print​(​10.20​ ​and​ ​20.30​) #both are true and second value taken
>Output is 20.3

print​(​0.0​ ​and​ ​20.30​) #First is false so first value


taken->Output is 0.0
print​(​20.30​ ​and​ ​0.0​) #Goes to till second and second value is
false so second is taken>Output is 0.0

print​(​0.0​ ​and​ ​0.0​) #First is false so first value is


taken->Output is 0.0

print​(​10.20​ ​or​ ​20.30​) #First is True so first value is


taken>Output is 10.2

print​(​0.0​ ​or​ ​20.30​) #Goes to till second and second is true


second value is taken->Output is 20.3

print​(​20.30​ ​or​ ​0.0​) #First is True so first value is


taken->Output is 20.3

print​(​0.0​ ​or​ ​0.0​) #Goes to till second and second is also


false and second value is taken>Output is 0.0

print​(​not​ ​10.20​) #-Not of true is false->Output is False

print​(​not​ ​0.0​) #Not of false is True>Output is True

Q.​ What is the output of expression inside print statement. Cross check
before running the program.
a = ​10.20
b - 1​ 0.20
print​(a ​is​ b) #True or False? True 10.20<256
print​(a ​is​ ​not​ b) #True or False? False
Why the Id of float values are different when the same value is
assigned to two different variables
ex: a = 10.5 b=10.5. but id will be same if I assign the variable
having float i.e. a=c then both a and c's Id are same

Q.​ Bitwise operation is not applicable between instances of float.


Why the Id of float values are different when the same value is
assigned to two different variables
ex: a = 10.5 b=10.5. but id will be same if I assign the variable
having float i.e. a=c then both a and c's Id are same
Object reusability concept is not applicable on float values.
Q.​ Membership operation
in, not in are two membership operators and it returns boolean value

print​(​'2.7'​ i
​ n​ '​ Python2.7.8'​) #True
print​(​10.20​ i​ n​ [​10​,​10.20​,​10​+​20j​,​'Python'​]) #True
print​(​10.20​ ​in​ (​10​,​10.20​,​10​+​20j​,​'Python'​)) # True
print​(​20.30​ ​in​ {​1​,​20.30​,​30​+​40j​}) # True
print​(​2.3​ ​in​ {​1​:​100​, ​2.3​:​200​, ​30​+​40j​:​300​}) # True
print​(​10​ ​in​ ​range​(​20​)) # True

You might also like