Exam PCAP All QuestionsBrowse all questions from this exam
Question 53

Which of the equations are True? (Choose two.)

    Correct Answer: A, D

    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.

Discussion
lukakiOptions: AD

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

baimus

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)

macxszOption: A

only correct answer: A. chr (ord (x)) = = x

TheFivePips

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.

palagus

I concur with lukaki. It depends on the value of x.

rbishun

So the question is written incorrectly...

rbishunOptions: AD

""" Notes: ord(str|byte) -> int chr(int) -> str """ x = 5 print(chr(ord('x')) == 'x') # True print(ord(chr(x)) == x) # True