简体   繁体   中英

Multiple line input in python

I'm wanting to be able to add multiple inputs and I'm pretty certain I'm going to need to create a loop for this, but not sure how to print multiple copies of the output.

Any help would be appreciated!

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

This one will be prompt user for new input until he will decide to terminate the program.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM