Lab Exercise 4
Lab Exercise 4
x = np.arange(1, 6)
y1 = np.array([10, 15, 7, 12, 9])
y2 = np.array([200, 300, 150, 250, 180])
# Add a legend
fig.legend(loc='upper left', bbox_to_anchor=(0.15, 0.85))
# Add a title
plt.title('Sales and Revenue Comparison')
if guess == number_to_guess:
print(f"Congratulations! You guessed the number in {guesses} attempts.")
except ValueError:
print("Invalid input. Please enter a valid number.")
Example simple calculator
def add(x, y):
return x + y
while True:
print("Select an operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice (1/2/3/4): ")
if choice == '1':
print(f"The result of addition: {add(num1, num2)}")
elif choice == '2':
print(f"The result of subtraction: {subtract(num1, num2)}")
elif choice == '3':
print(f"The result of multiplication: {multiply(num1, num2)}")
elif choice == '4':
print(f"The result of division: {divide(num1, num2)}")
except ValueError:
print("Invalid input. Please enter numeric values.")
else:
print("Invalid choice. Please select a valid operation.")