Which of the equations are True? (Choose two.)
Which of the equations are True? (Choose two.)
The equation 'chr (ord(x)) == x' is true because the ord() function returns the ASCII value of a character and chr() converts the ASCII value back to the character, making the original character unchanged. The equation 'ord (chr(x)) == x' is also true because chr() converts an integer to its corresponding ASCII character and ord() converts it back to the original integer. This makes A and D true under the respective conversions they perform.
A,D: x = 'x' print(chr(ord(x)) == x) #True print(ord(ord(x)) == x) # it will generate TypeError print(chr(chr(x)) == x) # it will generate TypeError print(ord(chr(x)) == x) # it will generate TypeError #Example2 x = 1 print(chr(ord(x)) == x) # it will generate TypeError print(ord(ord(x)) == x) # it will generate TypeError print(chr(chr(x)) == x) # it will generate TypeError print(ord(chr(x)) == x) #True
A D is what they intend, but the question should then read "which of these options could EVER be True, but never simulataneously" (which isn't a great question)
only correct answer: A. chr (ord (x)) = = x
I hate this question becuase the answer depends on what the variable x is. ord() expects a character and returns an int. chr() expects and int and returns a character.
I concur with lukaki. It depends on the value of x.
So the question is written incorrectly...
""" Notes: ord(str|byte) -> int chr(int) -> str """ x = 5 print(chr(ord('x')) == 'x') # True print(ord(chr(x)) == x) # True