PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 53


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

Show Answer
Correct Answer: AD

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

6 comments
Sign in to comment
lukakiOptions: AD
Nov 7, 2021

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
May 1, 2023

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
May 3, 2022

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

rbishunOptions: AD
Oct 31, 2021

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

rbishun
Oct 31, 2021

So the question is written incorrectly...

palagus
May 23, 2022

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

TheFivePips
Dec 6, 2023

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.