Project Level 1: Beginner
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
Project Description
This program asks the user to input a number and checks whether it is positive, negative, or zero.
How the Project Works
The program prompts the user to submit a number in the console. Once the user submits a number (e.g., -11), the program checks the sign of the number (e.g., negative, zero, or positive) and returns a message accordingly.
If the number is positive:
If the number is zero:
Prerequisites
Required Libraries:
Required Files: No files are required.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Once you code the project, compare it with our solutions below. We provide two solutions, one using if-elif-else and one using match-case, and compare the two to find out which one is better.
print("nivel 1: principiante lunes, ejercicio 2")
print()
num = int(input("ingrese un numero: "))
if num > 0:
print("El numero es positivo.")
elif num < 0:
print("El numero es negativo.")
else:
print("El numero es cero")
def main() -> None:
num: int = int(input("Enter a number: "))
match num :
case num if num > 0 :
print("The number is positive")
case num if num < 0 :
print("The number is negative")
case _ :
print("The number is zero")
if __name__ == '__main__':
main()