|
1 | 1 | """
|
2 |
| -Version: 0.1.0 |
| 2 | +Version: 0.1.1 |
3 | 3 | Author: Minemetero
|
4 | 4 | """
|
5 | 5 | import numpy as np
|
@@ -57,26 +57,32 @@ def get_range(prompt):
|
57 | 57 | def main():
|
58 | 58 | print("Welcome to the Equation Plotter!")
|
59 | 59 |
|
60 |
| - # Input equation from user |
61 | 60 | while True:
|
62 |
| - user_equation = input("Enter the equation in terms of 'x' (e.g., x**2 + 2*x + 1): ") |
| 61 | + # Input equation from user |
| 62 | + user_equation = input("Enter the equation in terms of 'x' (e.g., x**2 + 2*x + 1), or 'q' to quit: ") |
| 63 | + |
| 64 | + if user_equation.lower() in ['q', 'quit']: |
| 65 | + print("Goodbye!") |
| 66 | + break |
| 67 | + |
63 | 68 | try:
|
64 | 69 | # Test if the equation can be evaluated
|
65 | 70 | x = np.linspace(-10, 10, 10)
|
66 | 71 | y = eval(user_equation)
|
67 | 72 | if isinstance(y, np.ndarray):
|
68 |
| - break |
| 73 | + pass |
69 | 74 | except Exception as e:
|
70 | 75 | print(f"Invalid equation: {e}")
|
71 |
| - |
72 |
| - # Get x range from user |
73 |
| - x_range = get_range("Enter the x range as two numbers separated by a comma (e.g., -10, 10): ") |
74 |
| - |
75 |
| - # Get y range from user |
76 |
| - y_range = get_range("Enter the y range as two numbers separated by a comma (e.g., -10, 10): ") |
77 |
| - |
78 |
| - # Plot the equation |
79 |
| - plot_equation(user_equation, x_range, y_range) |
| 76 | + continue |
| 77 | + |
| 78 | + # Get x range from user |
| 79 | + x_range = get_range("Enter the x range as two numbers separated by a comma (e.g., -10, 10): ") |
| 80 | + |
| 81 | + # Get y range from user |
| 82 | + y_range = get_range("Enter the y range as two numbers separated by a comma (e.g., -10, 10): ") |
| 83 | + |
| 84 | + # Plot the equation |
| 85 | + plot_equation(user_equation, x_range, y_range) |
80 | 86 |
|
81 | 87 | if __name__ == "__main__":
|
82 | 88 | main()
|
0 commit comments