- 1
Paython
I need the explanation of the below question: x = ‘a’ If (x < ‘c’) X+= ‘b’ If (x > ‘z’): X+ = ‘c’ Print (x)
4 Answers
+ 1
X is not x, they are two different variables. x = 'a' (line one). The rest is there to confuse you.
But it could also be the keyboard helping you with caps at the beginning of a sentence.
+ 2
Mohamed Adli
x = 'a'
if (x < 'c'):
x += 'b'
if (x > 'z'):
x += 'c'
print (x)
x is less than c because Of ASCII value of a is less than c
so x = ab
Now 'ab' > 'z' here comparison will be on first character
ASCII value of a is less than z so this if block will not execute
So finally x = 'ab'
+ 2
Hi!
And also, in Python we can skip parentheses in the conditions (if they are not needed i.g. to group terms or to order operations):
if x < 'c':
x += 'b'
+ 1
Thank you