首页 > 解决方案 > python中的多行输入

问题描述

我希望能够添加多个输入,并且我很确定我需要为此创建一个循环,但不确定如何打印输出的多个副本。

任何帮助,将不胜感激!

mac_hex = input("Enter AP Ethernet Mac Address:")
mac_dec = int(mac_hex, 16)

print (" ")
print ("The Ethernet MAC address is " + (mac_hex))

print (" ")
print ("2.4 Ghz Radio MAC Addresses are as follows")
print ("Radio #1 = " + (hex(mac_dec+35)[2:]))
print ("Radio #2 = " + (hex(mac_dec+45)[2:]))
enter code here

标签: pythonpython-3.x

解决方案


while True:    
    mac_hex = input("Enter AP Ethernet Mac Address, leave empty to exit:")
    if not mac_hex.strip():
        break
    mac_dec = int(mac_hex, 16)

    print (" ")
    print ("The Ethernet MAC address is " + (mac_hex))

    print (" ")
    print ("2.4 Ghz Radio MAC Addresses are as follows")
    print ("Radio #1 = " + (hex(mac_dec+35)[2:]))
    print ("Radio #2 = " + (hex(mac_dec+45)[2:]))

推荐阅读