Robotics & Artificial Intelligence
What will be the output of the following statement for any two values of a & b entered by the user?
print(a) if a>b else print(b)
- It will give an error
- It will print the largest number
- It will print the smallest number
- None of these
Python Control Flow
1 Like
Answer
It will print the largest number
Reason — This is a shorthand if-else statement. If the condition a > b is true, the value of a is printed, otherwise, the value of b is printed. Therefore, the larger of the two numbers is printed.
Answered By
3 Likes
Related Questions
In Python, 'elif' can be used without 'if'.
Which of the following keywords is not used in conditional statements?
- if
- else
- elif
- go
Which of the following is the correct sequence to create multiple conditional statements?
- if else else
- if elif else
- if else elif
- if else if
Which logical operator(s) is/are used to combine multiple conditions in 'if' statement?
- and
- or
- not
- both a and b