A_0
PI = 3.141592
def number_input():
output = input("숫자 입력 : ")
return float(output)
def get_circumference(radius):
return 2 * PI * radius
def get_circle_area(radius):
return PI * radius * radius
print("get_circumference(10) : ", get_circumference(10))
print("get_circle_area(10) : ", get_circle_area(10))
1. **PI = 3.141592**: This line defines a constant `PI` with the approximate value of pi (π), which is a mathematical constant used in calculations involving circles.
2. **def number_input():** Defines a function named `number_input` that prompts the user to input a number. This function is defined but not used in this script.
- **output = input("숫자 입력 : "):** Asks the user to enter a number with the prompt "숫자 입력 : " (which translates to "Enter a number: ") and stores the input in the variable `output`.
- **return float(output):** Converts the input string to a floating-point number and returns it.
3. **def get_circumference(radius):** Defines a function that calculates the circumference of a circle given its radius.
- **return 2 * PI * radius:** Returns the circumference calculated using the formula \(2\pi r\), where \(r\) is the radius of the circle.
4. **def get_circle_area(radius):** Defines a function that calculates the area of a circle given its radius.
- **return PI * radius * radius:** Returns the area calculated using the formula \(\pi r^2\), where \(r\) is the radius of the circle.
5. **print("get_circumference(10) : ", get_circumference(10)):** Prints the circumference of a circle with radius 10 by calling the `get_circumference` function with `10` as the argument.
6. **print("get_circle_area(10) : ", get_circle_area(10)):** Prints the area of a circle with radius 10 by calling the `get_circle_area` function with `10` as the argument.
A_1
import module_B_0 as test
radius = test.number_input()
print(test.get_circumference(radius))
print(test.get_circle_area(radius))
1. **import module_B_0 as test**: Imports the module named `module_B_0` into the current script and gives it the alias `test`. This means you can access functions and variables defined in `module_B_0` by prefixing them with `test.` instead of `module_B_0.`.
2. **radius = test.number_input()**: Calls the `number_input` function from the `test` module (originally `module_B_0`). This function prompts the user to input a number, which is assumed to be the radius of a circle. The input number is then stored in the variable `radius`.
3. **print(test.get_circumference(radius))**: Prints the circumference of the circle by calling the `get_circumference` function from the `test` module with `radius` as the argument. This function calculates the circumference using the radius provided by the user.
4. **print(test.get_circle_area(radius))**: Prints the area of the circle by calling the `get_circle_area` function from the `test` module with `radius` as the argument. This function calculates the area using the radius provided by the user.
**Title: "Utilizing External Modules for Circle Calculations in Python"**
'개념 > 혼자 공부하는 파이썬' 카테고리의 다른 글
python) Student Class and Its Functionality (0) | 2024.12.20 |
---|---|
python) Downloading and Saving Content from the Web with Python (1) | 2024.11.20 |
python) how to use the module package in python? (0) | 2024.11.18 |
python) how to make the module to check about Entry point (1) | 2024.11.17 |
python) making custom module packages in python (0) | 2024.11.16 |