The general form of an if/else statement is as follows:
if «condition»: «if_block» else: «else_block»
The condition is checked only one time.
import math
num = int(input("Enter an integer: "))
if num < 0:
print("There is no square root of ", num,".", sep='')
else:
sq = math.sqrt(num)
print("The square root of ", num, " is ", sq, ".", sep='')
print("You entered ", num,".", sep='')
The condition is checked only one time. |
|