Add float demo
This commit is contained in:
parent
a562b395c4
commit
616c847cb8
29
0002_2/float.py
Normal file
29
0002_2/float.py
Normal 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)
|
||||||
Loading…
x
Reference in New Issue
Block a user