我有一个号码清单:nums = [12, 10, 32, 3, 66, 17, 42, 99, 20]
我的第一个任务是将每个数字打印在一个新行上,如下所示:
^{pr2}$
我可以通过创建一个for循环来打印列表中的整数来实现这一点:nums = [12, 10, 32, 3, 66, 17, 42, 99, 20]
for i in nums:
print(i)
现在我需要编写另一个for循环,在新行上打印每个数字及其平方,如下所示:The square of 12 is 144
The square of 10 is 100
The square of 32 is 1024
The square of 3 is 9
The square of 66 is 4356
The square of 17 is 289
The square of 42 is 1764
The square of 99 is 9801
The square of 20 is 40
到目前为止,我实际上已经能够打印出平方值,但无法单独将它们放在单独的行上。我还需要去掉值周围的括号。在
我的尝试:nums = [12, 10, 32, 3, 66, 17, 42, 99, 20]
for i in nums:
print(i)
squared = [ ]
for i in nums:
squared.append(i * i)
print("The square of", i, "is", squared)
导致&