Evaluate a function near a point where its formula breaks, and watch the limit appear.
What to build
Read some small values of x and print sin(x)/x for each, to see that the values approach 1.
Requirements
- Read one line of numbers, none of them 0.
- For each x print one line in the exact format shown.
- Show the value with 6 decimal places.
Input
One line with 1 to 8 decimal numbers x, separated by spaces. None is 0.
Output
One line per x: x = X sin(x)/x = V, where X is the number exactly as it was written and V has 6 decimal places. There are two spaces before sin.
Constraints
Each |x| is at most 10. Use radians (Python's sin).
Example
Input:
1 0.1 0.01
Output:
x = 1 sin(x)/x = 0.841471
x = 0.1 sin(x)/x = 0.998334
x = 0.01 sin(x)/x = 0.999983
Why it works
At x = 0 the formula is 0 ÷ 0, but for x close to 0 it gives values close to 1. A limit looks at the neighbourhood of the point, and a table of values shows the trend.
Examples
1 0.1 0.01
x = 1 sin(x)/x = 0.841471 x = 0.1 sin(x)/x = 0.998334 x = 0.01 sin(x)/x = 0.999983
0.001
x = 0.001 sin(x)/x = 1.000000
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Use `from math import sin` and the expression `sin(x) / x`.
Hint 2
Read the numbers with `input().split()` and convert each one with `float`.
Hint 3
Print the original text of x, so 0.10 stays 0.10, and format the value with `:.6f`.
Solution
Show one correct solution (try it yourself first)
from math import sin
for t in input().split():
x = float(t)
print(f"x = {t} sin(x)/x = {sin(x) / x:.6f}")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step