-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
22 lines (19 loc) · 878 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while True:
try:
# Asking user to enter three numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
# Check if all three numbers are positive
if num1 > 0 and num2 > 0 and num3 > 0:
total_sum = num1 + num2 + num3
print(f"The sum of the numbers is: {total_sum}")
else:
print("Only positive numbers are accepted.")
# Asking user if they want to perform the operation again
repeat = input("Do you want to perform the operation again? (yes/no): ").strip().lower()
if repeat != 'yes':
print("Terminating the program.")
break
except ValueError:
print("Invalid input. Please enter numerical values.")