I have a code snippet inline which has to be modified so that it uses one print statement.
age=12
if age < 18:
if age < 12:
print('kid')
else:
print('teenager')
else:
print('adult')
I tried to approach this problem by putting if conditions in a single print statement without use of extra variable.
age=12
print('kid' if age<18 and age<12 else 'teenager' if age<18 and age>=12 else 'adult')
The result of the modified code snippet is coming same as that of the original code snippet but wanted to confirm if its the right approach according to the question or should i use an extra variable and store the outcome of each if statement and print the variable at the end of if condition.