1.2python
1.2python
WORKSHEET 1.2
1. Aim:
2. Source Code:
d. Write a program that uses the break statement to exit a loop when
a specific condition is met.
while True:
if number == 0:
print("You entered 0. Exiting the loop.")
break
print(f"You entered: {number}")
print("Loop has been exited.")
DEPARTMENT OF
COMPUTER SCIENCE
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
if choice == '1':
print(f"{num1} + {num2} = {add(num1, num2)}")
elif choice == '2':
print(f"{num1} - {num2} = {subtract(num1, num2)}")
elif choice == '3':
print(f"{num1} * {num2} = {multiply(num1, num2)}")
elif choice == '4':
print(f"{num1} / {num2} = {divide(num1, num2)}")
else:
print("Invalid input! Please select a valid operation.")
3. Screenshot of Outputs: