YouTip LogoYouTip

Python3 If Example

# Python3.x Python if Usage Examples [![Image 3: Document Object Reference Manual](#) Python3 Examples](#) The following examples use the **if...elif...else** statement to determine whether a number is positive, negative, or zero: ## Example (Python 3.0+) # Filename : test.py# author by : www..com# User input number num = float(input("Enter a number: "))if num>0: print("Positive number")elif num == 0: print("Zero")else: print("Negative number") Executing the above code produces the following output: Enter a number: 3Positive number We can also use a nested if statement to achieve the same: ## Example (Python 3.0+) # Filename :test.py# author by : www..com# Nested if statement num = float(input("Enter a number: "))if num>= 0: if num == 0: print("Zero")else: print("Positive number")else: print("Negative number") Executing the above code produces the following output: Enter a number: 0Zero [![Image 4: Document Object Reference Manual](#) Python3 Examples](#)
← Python3 Ascii CharacterPython3 Armstrong Number β†’