首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >python中的多行输入

python中的多行输入
EN

Stack Overflow用户
提问于 2018-07-04 02:22:17
回答 2查看 77关注 0票数 -2

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

任何帮助都将不胜感激!

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2018-07-04 02:31:59

代码语言:javascript
复制
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:]))
票数 0
EN

Stack Overflow用户

发布于 2018-07-04 02:57:11

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

代码语言:javascript
复制
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:]))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51160839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档