0
What is the output of the following code and Why:
x='a' if(x<'c'): x+='b' if(x>'z'): x+='c' print (x)
11 Answers
+ 3
The ascii value of 'a' is less than ascii value of 'c'
x becomes 'ab'
'ab' > 'z' is false (it checks by ascii value of first character)
Therefore x remains 'ab'
You can check ascii value by ord()
+ 3
You can find the output by **running** the code: Go to Code section, click +, select the programming language, insert your code, click Run.
Check the spelling of print()
+ 2
The output would be
ab
+ 2
You can remove the other print() when you have understood how the code works
+ 1
put a print() in each if-block to see which one is executed
+ 1
Ya as 'a' is the first character
0
Output is ab But How ??? It must be 'abc'
0
Ok I understand it check only a of 'ab' in condition x>'c'
0
Thanks,I understand but i only want to print the x value at last
0
Ok
0
Purva Bharadiya it only check the value of a in 'ab'.m'I right?