-1
# This program says hello and asks for my name, then repeats it.
print('Hello world!')
print('What is your name?')
myName = input()

while 
    print('It is nice to meet you, ' + myName)

我的问题是我在哪里放什么?我正在尝试学习如何使用while循环,但我不知道在 while 之后要放什么来让它永远重复你的名字。提前致谢!

4

2 回答 2

0

您可以使用将始终评估为 的任何条件True。最明显(因此更可取)的方式是

while True:
    print('It is nice to meet you, ' + myName)

另请注意,您不需要使用字符串连接print()

print('It is nice to meet you,', myName)
于 2013-09-27T18:57:50.210 回答
0

如果要输入一个名称并无限期打印,请使用:

print('Hello world!')
print('What is your name?')
myName = input()

while True:
    print('It is nice to meet you, ' + myName)

如果你想输入一个名字,打印出来,然后输入另一个,依此类推,使用:

print('Hello world!')
while True:
    print('It is nice to meet you, ' + input('What is your name? '))
于 2013-09-27T18:59:26.807 回答