# 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
循环,但我不知道该怎么做才能让它永远重复你的名字。
提前谢谢!
答案 0 :(得分:0)
您可以使用始终评估为True
的任何条件。
while True:
print('It is nice to meet you, ' + myName)
另请注意,您不需要将字符串连接与print()
:
print('It is nice to meet you,', myName)
答案 1 :(得分: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? '))