Add float demo

This commit is contained in:
Henry Lin 2025-08-27 15:09:10 +08:00
parent a562b395c4
commit 616c847cb8

29
0002_2/float.py Normal file
View File

@ -0,0 +1,29 @@
# 示例:浮点数的定义和运算
pi = 3.14159 # 定义一个浮点型变量pi
radius = 5.0 # 定义另一个浮点型变量radius
# 计算圆的面积
area = pi * radius ** 2 # 使用浮点数进行运算
print("圆的面积是:", area) # 输出结果
"""
基础定义一个浮点型变量表示你的身高例如1.75并打印出来
"""
height = 1.75
print(height)
"""
应用计算一个圆的周长已知圆的半径为7.5
"""
pi = 3.14
radius = 7.5
perimeter = 2 * pi * radius
print("圆的周长是:", perimeter)
"""
挑战编写一个程序接收用户输入的圆的半径浮点数然后计算并打印出圆的面积
"""
pi = 3.14
radius = float(input("请输入圆的半径:"))
area = pi * radius ** 2
print("圆的面积是:", area)