树莓派Pico W编程与LED项目实战
1. 编程示例
在编程学习中,我们会遇到各种有趣的示例,下面为大家详细介绍一些常见的编程示例。
1.1 电阻计算程序
此程序可依据用户输入的电阻连接模式(串联或并联),计算总电阻值。
mode = mode.lower()
#
# Read the resistor values and calculate the total
#
resistor = 0.0
if mode == 's':
for n in range(0,N):
s = "Enter resistor " + str(n+1) + " value in Ohms: "
r = int(input(s))
resistor = resistor + r
print("Total resistance = %d Ohms" %(resistor))
elif mode == 'p':
for n in range(0,N):
s = "Enter resistor " + str(n+1) + " value in Ohms: "
r = float(input(s))
resistor = resistor + 1 / r
print("Total resistance = %.2f Ohms" %(1 / resistor))
#
# Check if the user wants to exit
#
yn = input("\nDo you want to
超级会员免费看
订阅专栏 解锁全文
6万+

被折叠的 条评论
为什么被折叠?



