输入打印输出

时间:2013-06-13 03:33:35

标签: python python-3.x

当用户输入它时,我试图让它打印出漂亮和丑陋,但它只会记住用户的最后一个输入。

n = int(input('How many groups would you like to configure today?'))
for i in range(n):
    group = input('Group {}: '.format(i+1))

def uqdfa(money):
    return('permit ' + money)

if group == 'nice':
    print (uqdfa('233.10.10.10'))
    print (uqdfa('233.10.10.11'))

if group == 'ugly':
    print (uqdfa('233.10.10.16'))
    print (uqdfa('233.10.10.17'))

1 个答案:

答案 0 :(得分:3)

if块应位于for循环内。

def uqdfa(money):
    return('permit ' + money)

n = int(input('How many groups would you like to configure today?'))
for i in range(n):
    group = input('Group {}: '.format(i+1))
    if group == 'nice':
        print (uqdfa('233.10.10.10'))
        print (uqdfa('233.10.10.11'))

    elif group == 'ugly':
        print (uqdfa('233.10.10.16'))
        print (uqdfa('233.10.10.17'))