Question #126609

Write a Python program that gets a number using keyboard input. (Remember to use input for Python 3 but raw_input for Python 2.)

If the number is positive, the program should call countdown. If the number is negative, the program should call countup. Choose for yourself which function to call (countdown or countup) for input of zero.

Provide the following.

  • The code of your program.
  • Output for the following input: a positive number, a negative number, and zero.
  • An explanation of your choice for what to call for input of zero.

Expert's answer

This is code:

print('Enter a number: ')
num = int(input())


if num >= 0:
    num -= 1
else:
    num += 1


print(num)

Output:

2
1


0
-1


-5
-4

Explanation about zero: Because I think, that zero is more positive, than negative.


LATEST TUTORIALS
APPROVED BY CLIENTS