Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python While循环星号_Python_Loops_While Loop - Fatal编程技术网

Python While循环星号

Python While循环星号,python,loops,while-loop,Python,Loops,While Loop,重新键入并运行,注意错误行为。然后修复代码中的错误,它应该打印num_星号 while num_printed != num_stars: print('*') num_printed = 0 num_stars = int(input()) ''' Your solution goes here ''' while (num_printed < num_stars): print('*') num_printed += 1 下面是我输入的代码。我得到一个无限循

重新键入并运行,注意错误行为。然后修复代码中的错误,它应该打印num_星号

while num_printed != num_stars:
    print('*')
num_printed = 0

num_stars = int(input())

''' Your solution goes here '''
while (num_printed < num_stars):
   print('*')
   num_printed += 1
下面是我输入的代码。我得到一个无限循环,因此没有答案。请帮帮我!谢谢

num_stars = 3

num_printed = 0

while(num_printed != num_stars):

    print(num_stars*'*')
您可能需要:

num_stars = 3
print(num_stars * '*')
或:

num_stars=3
打印数量=0
而(打印数量<星星数量):
打印(“*”)
打印数+=1

取决于您尝试执行的操作。

重新键入或复制,然后运行以下代码;注意不正确的行为。然后修复代码中的错误,它应该打印num_星号

while num_printed != num_stars:
    print('*')
num_printed = 0

num_stars = int(input())

''' Your solution goes here '''
while (num_printed < num_stars):
   print('*')
   num_printed += 1
num\u printed=0
num_stars=int(输入())
“你的解决方案在这里”
而(打印数量<星星数量):
打印(“*”)
打印数+=1

您永远不会增加打印数量。另外,不要选中
=,检查
>
以获得更大的检查安全性。
打印(num_stars*'*')
打印num_stars星号。不需要
while
循环。肖恩·皮安卡:这就是你的意思吗?num_stars=3 num_printed=0 while(num_printed>num_stars):print(num_stars*'*')程序没有生成输出。zvone:我必须使用while循环,因为3不是唯一要检查的num_stars值。可能值得强调的是,这两个代码段并不相等。谢谢!这是我需要的第二个!