Integer to Boolean
I'm new to python and I pray that I'm not bashed for this question... As a
computer science major I feel it's only right to ask at least ONE question
on stackoverflow.
How do I use an integer value as a boolean without the use of functions?
Here's the question:
You will be given a series of mathematical and logical tasks. Implement
these ONLY using variables and operators. No loops, conditionals,
functions or data structures should be used. You will only be working with
the basic data types: Integer, Float, String, and Boolean.
Operators that you can use: +, -, , /, %, *, //, ==, !=, <>, >, <, >=, <=,
=, +=, -=, =, /=, %=, *=, //=, and, or, not, &, |, ^, ~, <<, >>
Given:
a = 5
b = 7
Task: Implement xor (abbreviation for 'exclusive or'). Xor should be true
if a and b are not the same. Store the value of a xor b in a variable
named output. Example: 2 xor 9 = True
I know it would be extremely easy to do: output = bool(a^b)
However... I can't use functions :/
a^b=12 which is a true value... I just don't know how to get that to
represent a boolean value.
No comments:
Post a Comment