当前位置: 首页 > 图灵资讯 > 行业资讯> python怎么计算面积?

python怎么计算面积?

发布时间:2026-01-28 21:48:28

用Python计算面积的知识点:

1、 长方形面积和三角形面积使用map,因为用户的多个参数输入需要从终端接收(int, raw_input().split()这样

2. 圆面积只想保留小数点后两位,就用了 %.2f

#!/usr/bin/python
#-*-coding:utf-8-*-
name=raw_input("Pleaseinputyournamehere:")
ifname=='':
print("wedon'tlikeanonymous")
else:
choose=input("Whichshapewouldyoulitochoose11:Rectangle,2:Square,3:Triangleor4Round?:")
ifchoose==1:
width,height=map(int,raw_input("Inputwidthandheighthere,like58:").split())
print("Area=%d"%(width*height))
elifchoose==2:
length=input("Inputwidthandheighthere,like4:")
print("Area=%d"%length**2)
elifchoose==3:
width,height=map(int,raw_input("Inputwidthandheighthere,like58:").split())
print("Area=%d"%(width*height/2))
elifchoose==4:
diameter=input("Inputdiameterherelike3:")
print("Area=%.2f"%(3.14*(diameter/2)**2)
else:
print("Invalidchoose")

相关文章

python怎么计算面积?

python怎么计算面积?

2026-01-28
在mac系统怎么编写Python?

在mac系统怎么编写Python?

2026-01-28
Python中怎么转换人民币和美元?

Python中怎么转换人民币和美元?

2026-01-28
python转义字符失效的原因是什么?

python转义字符失效的原因是什么?

2026-01-28
python怎么用画散点图?

python怎么用画散点图?

2026-01-27
python转义符怎么打?

python转义符怎么打?

2026-01-27