2024 3 31 python的学习过程

  1. Please enter the row and column [m, n] of the matrix, and randomly generate a matrix of mxn size (here it is required to store in the form of a list). Please realize the transposition of the matrix. (Code+result screenshot)

原题如上:

1.

# 第二题
import random
m=int(input("please input the row"))
n=int(input ("please input the column"))


x=m*n
d=list()
d=[random.randint(1,100) for _ in range(x)]

i=0

for d in n:
    print(d[i])
    i+=1

报错:for d in n:
TypeError: 'int' object is not iterable

解决:是for循环的迭代问题

问题:

如何将随机数输出在同一行;

解决:

学会了用enumerate函数同时返回列表中数的索引和值,在print中修改end就可以在同一行中输出,

问题:为什么没有对齐

解决:破案了,数列第一项索引是0;

爽了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值