【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】