AcWing语法基础课【Python3】版题解-顺序语句

【AcWing 1. A+B】

这种方式输入了2个int型的数字,split()代表以空格隔开

a, b = map(int, input().split())
print(a + b)

 【AcWing 608. 差】

a = int(input())
b = int(input())
c = int(input())
d = int(input())
print("DIFERENCA = %d" %(a * b - c * d))

%c  格式化字符及其ASCII码
%s  格式化字符串
%d  格式化整数
%f  格式化浮点数字,可指定小数点后的精度

【AcWing 604. 圆的面积】

pi=3.14159
R=float(input(""))
print("A=%.4f" %(pi*R**2))

'%.nf'%A是格式化浮点数字,可以把浮点数A转换成保留n位小数的字符串。

import math
R = float(input())
A = round(math.pi, 5)*R**2
5的意思是取到pi的第5位
print(f'A={round(A, 4)}')

导入math标准库,使用math.π常量,round(A, n)返回浮点数A保留n位小数(四舍五入)的值。

【AcWing 606. 平均数1】


                
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值