Answer to Question #126609 in Python for Ola Unwana

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.
1
Expert's answer
2020-07-20T14:27:22-0400

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.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS