0
点赞
收藏
分享

微信扫一扫

SCAU pyhon语言程序设计——实验一

捡历史的小木板 2022-04-15 阅读 41
python

 

1:

pi=3.1415926
r=3.2
int(pi)
int(r)
print('{:.2f}'.format(r*r*pi))
print('{:.2f}'.format(2*pi*r))

2:

a=int(input(''))
b=int(input(''))
c=int(input(''))
l=(a+b+c)/2
s=(l*(l-a)*(l-b)*(l-c)) **0.5
print(s)

3:

a=(input())
b=(input())
c=(input())
if not a.isdigit():
    print('a边请输入数值')
if not b.isdigit():
    print('b边请输入数值')
if not c.isdigit():
    print('c边请输入数值')
a=int(a)
b=int(b)
c=int(c)
l=(a+b+c)/2
s=(l*(l-a)*(l-b)*(l-c)) **0.5
print(s)

4:

a=(input())
b=(input())
c=(input())
if not a.lstrip('-').isdigit():
    print('a边请输入数值')
if not b.lstrip('-').isdigit():
    print('b边请输入数值')
if not c.lstrip('-').isdigit():
    print('c边请输入数值')
a = int(a)
b = int(b)
c = int(c)
if c+b<a or c+a<b or a+b<c:
    print('此三边无法构成三角形')
if a<0:
    print('a边不能为负数')
if b < 0:
    print('b边不能为负数')
if c < 0:
    print('c边不能为负数')
l=(a+b+c)/2
s=(l*(l-a)*(l-b)*(l-c)) **0.5
if s > 0:
    print(s)

5:

lst=[89,45,-34,23.1,98,33]
max=lst[0]
min=60
j=0
for i in range(6):
    if lst[i]<min:
        j=j+1
    if lst[i]>max:
        max=lst[i]
print(j)
print(max)

6:

month=[31,28,31,30,31,30,31,31,30,31,30,31]
j=int(input())
for i in range(12):
    if i==j-1:
        print(month[i])

python要特别注意if下行的缩进,否则会报错。还有注意转换数据格式,不然也会报错

举报

相关推荐

0 条评论