当用户输入它时,我试图让它打印出漂亮和丑陋,但它只会记住用户的最后一个输入。
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'))
答案 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'))