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
Show 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
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.
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 ...
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...
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...
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 ...
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...
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...