93,725 views
1 vote
1 vote
Using a conditional expression, write a statement that increments numUsers if updateDirection is 1, otherwise decrements numUsers. Ex: if numUsers is 8 and updateDirection is 1, numUsers becomes 9; if updateDirection is 0, numUsers becomes 7.

User Mrigesh Priyadarshi
by
2.7k points

1 Answer

5 votes
5 votes

Answer:

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

Explanation:

This is going to give you the +1 or -1 depending on what the update_direction is = to. If you have a different direction then just make it -= to that.

User Muued
by
3.4k points