设计一个程序,用户可以通过键盘数字选择计算的三角函数(正弦值、余弦值、反正切值,弧度值),选择后,提示用户输入需要计算的角度值,最后给出计算结果
时间: 2024-02-23 21:58:47 浏览: 21
好的,以下是 Python 代码实现:
```python
import math
# 提示用户选择计算的三角函数
print("请选择计算的三角函数:")
print("1. 正弦值")
print("2. 余弦值")
print("3. 反正切值")
print("4. 弧度值")
# 获取用户的选择
choice = int(input("请输入选择的数字:"))
# 根据用户的选择计算三角函数
if choice == 1:
# 计算正弦值
angle = float(input("请输入角度值:"))
radian = math.radians(angle)
result = math.sin(radian)
print("正弦值为:", result)
elif choice == 2:
# 计算余弦值
angle = float(input("请输入角度值:"))
radian = math.radians(angle)
result = math.cos(radian)
print("余弦值为:", result)
elif choice == 3:
# 计算反正切值
value = float(input("请输入需要计算的值:"))
result = math.atan(value)
print("反正切值为:", result)
elif choice == 4:
# 计算弧度值
angle = float(input("请输入角度值:"))
result = math.radians(angle)
print("弧度值为:", result)
else:
print("输入有误,请输入正确的数字!")
```
运行程序后,用户可以根据提示选择需要计算的三角函数,并输入需要计算的角度值或值,程序会自动计算并输出结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)