2025-08-27 15:09:10 +08:00

30 lines
803 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 示例:浮点数的定义和运算
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)