python中的多行输入

时间:2018-07-03 18:22:17

标签: python python-3.x

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

任何帮助将不胜感激!

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

2 个答案:

答案 0 :(得分:0)

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:]))

答案 1 :(得分:0)

这将提示用户输入新的内容,直到他决定终止程序为止。

mac_hex = ''
while mac_hex != 'quit':
    mac_hex = input("Enter AP Ethernet Mac Address:")
    if mac_hex != 'quit':
        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:]))