Clinton Vlasak Clinton Vlasak - 2 years ago 91
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)

Answer Source

The correct statement would be:

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

For reference, see Conditional Expressions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download