Clinton Vlasak Clinton Vlasak - 1 month ago 7x
Python Question

Conditional expression and incrementing/decrementing a variable

I'm doing some practice and need a little help for the problem below. I'm not sure how to put the if statement into a conditional expression, or if i'm incrementing correctly. Thanks

num_users = 8
update_direction = 3

num_users =
if update_direction ==3:
num_users= num_users + 1
num_users= num_users - 1

print('New value is:', num_users)


The correct statement would be:

num_users = num_users + 1 if update_direction == 3 else num_users - 1

For reference, see Conditional Expressions.