如何打破这个while循环?[python]
当你在while循环中输入一个数字值时,循环结束,程序也结束。但是,当我键入“break”时,我得到了一个无效的语法错误:(。对于错误的编码,很抱歉,这是我第一次如何打破这个while循环?[python],python,loops,while-loop,Python,Loops,While Loop,当你在while循环中输入一个数字值时,循环结束,程序也结束。但是,当我键入“break”时,我得到了一个无效的语法错误:(。对于错误的编码,很抱歉,这是我第一次 print('Hello, world!') print('What is your name?') myName = input() print('It is nice to met you, '+ myName) print('The length of your name is:') print(len(myName)) pri
print('Hello, world!')
print('What is your name?')
myName = input()
print('It is nice to met you, '+ myName)
print('The length of your name is:')
print(len(myName))
print('What is your age?')
myAge=input()
if myAge.isdigit():print('You will be ' + str(int(myAge) + 1) + ' in "one" year')
else: print('that is not a number. Lets try again, what is your age?')
C = 0
while (C<=3):
myAge2=input()
C+=1
if myAge2.isdigit():print('You will be ' + str(int(myAge2) + 1) + ' in "one" year')
break
else: print('Try again')
print('Hello,world!')
打印('你叫什么名字?')
myName=input()
打印(‘很高兴认识你,’+myName)
print('您姓名的长度为:')
打印(len(myName))
打印(“您的年龄是多少?”
myAge=input()
if myAge.isdigit():print('一年内您将成为'+str(int(myAge)+1)+')
else:print('这不是一个数字。让我们再试一次,您的年龄是多少?')
C=0
而(C缩进以应用正确的break
如果myAge2.isdigit():
打印('一年内'+str(int(myAge2)+1)+')
打破
其他:
打印('重试')
我试图简化代码:
print('Hello, world!\nWhat is your name')
myName = input()
print('It is nice to met you, {}.\nThe length of your name is: {}'.format(myName, len(myName)))
print('What is your age?')
myAge=input()
if myAge.isdigit():
print('You will be ' + str(int(myAge) + 1) + ' in "one" year')
else:
print('that is not a number. Lets try again, what is your age?')
myAge2=input()
while myAge2.isdigit():
print('You will be ' + str(int(myAge2) + 1) + ' in "one" year')
break
else:
print('Try again')
代码缩进有问题,否则一切都正常工作
print('Hello,world!')
打印('你叫什么名字?')
myName=input()
打印(‘很高兴认识你,’+myName)
print('您姓名的长度为:')
打印(len(myName))
打印(“您的年龄是多少?”
myAge=input()
如果myAge.isdigit():
打印('您将在'一'年'内'+str(int(myAge)+1)+')
其他:
打印('这不是一个数字。让我们再试一次,您的年龄是多少?')
C=0
虽然(C)缩进中断在if之后,但也要在if之后删除代码块,并将else添加到换行符中。请添加错误消息。