For loop 我如何重写a';对于循环';作为';while循环';用python?
这是一个循环:For loop 我如何重写a';对于循环';作为';while循环';用python?,for-loop,while-loop,For Loop,While Loop,这是一个循环: for c in "Hi there": print(c.upper()) 这是我作为while循环重写的尝试: phrase = "Hi there" while len.phrase > 0 print (c.upper()) 使用迭代器 phrase = "Hi there" limit = len(phrase); itery =0; while itery<limit: print (phrase[itery].upper())
for c in "Hi there":
print(c.upper())
这是我作为while循环重写的尝试:
phrase = "Hi there"
while len.phrase > 0
print (c.upper())
使用迭代器
phrase = "Hi there"
limit = len(phrase);
itery =0;
while itery<limit:
print (phrase[itery].upper());
itery+=1;
短语=“你好”
限制=长度(短语);
itery=0;
虽然itery这里有几件事我看错了
首先,您忘了在while语句末尾使用冒号
while len.phrase > 0:
其次,执行此任务的更有效方法如下:
while 1:
因为1永远是真的(在Python的情况下),它将执行一个无限循环,就像您之前的尝试似乎打算做的那样