Pair of Negative Values - Python Programming Exercise

In this exercise, you will develop a Python program that prompts the user for two numbers and checks if both of them are negative. This task will help you practice using conditional statements in Python to evaluate multiple user inputs and determine their characteristics, such as whether both numbers are negative. By completing this exercise, you will gain experience working with logical operators and if-else conditions to make decisions based on user input. Mastering these concepts is crucial for developing more complex Python programs that require data validation and decision-making processes.

 Category

Mastering Flow Control

 Exercise

Pair Of Negative Values

 Objective

Develop a Python program that prompts the user for two numbers and checks if both numbers are negative.

 Example Python Exercise

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

# Prompt the user to enter the second number
num2 = float(input("Please enter the second number: "))

# Check if both numbers are negative and display the result
if num1 < 0 and num2 < 0:
    print(f"Both {num1} and {num2} are negative.")
else:
    print(f"Both numbers are not negative.")

 Output

Please enter the first number: -5
Please enter the second number: -3
Both -5.0 and -3.0 are 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.

  •  Single or Pair of Negative Values

    In this exercise, you will develop a Python program that prompts the user for two numbers and checks whether both are negative, only one is negative...

  •  Factors and Multiples

    In this exercise, you will develop a Python program that displays the numbers from 1 to 500 that are multiples of both 3 and 5 on the screen. You...

  •  Repeated Value

    In this exercise, you will develop a Python program that prompts the user for a number and a quantity, then displays that number repeated as many...

  •  Access Code

    In this exercise, you will develop a Python program that prompts the user to enter their login and password (both must be integer numbers). The p...

  •  Access Code V2

    In this exercise, you will develop a Python program that prompts the user for their login and password, both of which must be integers. The progr...

  •  Multiple Divisions

    In this exercise, you will develop a Python program that prompts the user for two numbers and displays their division and remainder. If 0 is entered as ...