0

当用户输入它们时,我试图让它打印出来又好又丑,但它只记住用户的最后输入。

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'))
4

1 回答 1

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'))
于 2013-06-13T03:36:50.030 回答