Positive and Negative Numbers - Python Programming Exercise

In this exercise, you will develop a Python program that prompts the user to input a number and then determines if the number is positive or negative. This task introduces you to conditional statements in Python, teaching you how to use if and else statements to evaluate conditions and make decisions based on user input. By completing this exercise, you will strengthen your understanding of Python syntax and the use of conditional logic. This is an essential skill for creating dynamic Python programs that respond differently based on the user's input. Mastering this concept will help you build more interactive and intelligent programming solutions using Python.

 Category

Mastering Flow Control

 Exercise

Positive And Negative Numbers

 Objective

Develop a Python program that prompts the user to input a number and then determines if the number is positive or negative.

 Example Python Exercise

 Copy Python Code
# Prompt the user to enter a number
num = float(input("Please enter a number: "))

# Determine if the number is positive or negative and display the result
if num > 0:
    print(f"The number {num} is positive.")
elif num < 0:
    print(f"The number {num} is negative.")
else:
    print("The number is zero.")

 Output

Please enter a number: -5
The number -5.0 is negative.

 Share this Python Exercise

 More Python Programming Exercises of Mastering Flow Control

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Multiply Unless Zero

    In this exercise, you will develop a Python program that prompts the user for a number. If the number is not zero, the program will ask for a second ...

  •  Division When Non-Zero

    In this exercise, you will develop a Python program that prompts the user for two numbers. The program will display their division if the second numb...

  •  Conditional Division (Using Else)

    In this exercise, you will develop a Python program that prompts the user for two numbers. The program will display their division if the second numb...

  •  Largest Among Three Values

    In this exercise, you will develop a Python program that prompts the user to input three numbers and then determines and displays the largest one. This ...

  •  Loop Until Zero

    In this exercise, you will develop a Python program that prompts the user for a number "x" and calculates the result of 10 * x. The program will display...

  •  Loop Until Zero (Using While)

    In this exercise, you will develop a Python program that prompts the user for a number "x" and displays 10*x. This exercise is perfect for practicing user inpu...