分别打印每个数字python_Python For循环,在单独的Lin上打印每个数字及其平方

我有一个号码清单: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)

导致&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值