Paython | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
- 1

Paython

I need the explanation of the below question: x = ā€˜aā€™ If (x < ā€˜cā€™) X+= ā€˜bā€™ If (x > ā€˜zā€™): X+ = ā€˜cā€™ Print (x)

3rd Jun 2022, 1:18 PM
Mohamed Adli
4 Respostas
+ 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.
3rd Jun 2022, 5:56 PM
Paul
Paul - avatar
+ 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'
3rd Jun 2022, 1:29 PM
AĶ¢J
AĶ¢J - avatar
+ 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'
3rd Jun 2022, 2:51 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Thank you
3rd Jun 2022, 1:40 PM
Mohamed Adli