同时使用原始输入创建一个无限循环

2024-04-25 08:34:37 发布

您现在位置:Python中文网/ 问答频道 /正文

在这些行中:

foo = []

a = foo.append(raw_input('Type anything.\n'))
b = raw_input('Another questions? Y/N\n')

while b != 'N':
    b = foo.append(raw_input('Type and to continue, N for stop\n'))
    if b == 'N': break

print foo

如何断环? 谢谢!在


Tags: andtoforinputrawiffootype
3条回答

在列表.追加不返回。在

a = raw_input('Type anything.\n')
foo = [a]
b = raw_input('Another questions? Y/N\n')

while b != 'N':
    b = raw_input('Type and to continue, N for stop\n')
    if b == 'N': break
    foo.append(b)

这就是方法

foo = []

a = raw_input('Type anything.\n')
foo.append(a)
b = raw_input('Another questions? Y/N\n')

while b != 'N':
    b = raw_input('Type and to continue, N for stop\n')
    if b == 'N': break
    foo.append(raw_input)

print foo

{cd1>添加到最后一个元素的检查:

while b != 'N':
    foo.append(raw_input('Type and to continue, N for stop\n'))
    if foo[-1] == 'N': break   # <---- Note foo[-1] here

相关问题 更多 >

    热门问题