A type of data that can have one of two possible values - usually either true or false.
Computers can perform logical computations. Logic expressions compute boolean values, represented by the special values True and False.
Boolean values are the two constant objects False and True. In numeric contexts, a computer equates the value True to 1 and False to 0 when combining integers and booleans.
Multiplying a number by True produces the same number, and multiplying by False produces 0.
Let’s visit the examples :
print("Adding True + True = " , True + True) print("Adding False + False = " , False + False) print("Multiplying 100 * False = " , 100 * False) print("1 + True = " ,1 + True) print("1- False = ", 10 - False) #Assigning boolean values to variables right = True left = False
Let's look at another example:
count = 80
on_time = True
Run below code and see the result.
Try changing on_time to False to see your score again.
count = 80 on_time = True print("Your count is " + str(count * on_time))
A mathematic question needs to be solved step by step and each step has different marks as shown below:
# keeping entire page clean without scratches and scribbles
clean_page = 1 mark
# writing correct formula for the mathematical question
writing_correct_formula = 1 mark
# applying the values to the formula
putting_correct_value_in_formula = 1 mark
# deriving the equation
deriving_formula = 2 marks
# writing the correct answer by highlighting it
writing_correct_answer = 3 marks
Boolean values given are shown below. Print the final value.
clean_page = True
writing_correct_formula = True
putting_correct_value_in_formula = True
deriving_formula = True
writing_correct_answer = True
clean_page = True writing_correct_formula = True putting_correct_value_in_formula = True deriving_formula = True writing_correct_answer = True print(clean_page + writing_correct_formula + putting_correct_value_in_formula + deriving_formula * 2 + writing_correct_answer * 3)