【发布时间】:2018-03-03 00:10:42
【问题描述】:
就像下面的 C++ 代码一样,我如何使用 Python 在二维数组中输入元素?请帮助在 Python3 中编写相同的程序。
int main()
{
int s = 3;
int a[s][s];
cout<<"Enter 9 Element in Square Matrix";
for(int i =0;i<s;i++)
{
for(int j =0; j<s;j++)
{
cin>>a[i][j];
}
}
cout<<"You Entered";
for(int i =0;i<s;i++)
{
for(int j =0; j<s;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}
Output:
Enter 9 Elements in Square Matrix
1
2
3
4
5
6
7
8
9
You Entered:
1 2 3
4 5 6
7 8 9
如果程序有错误,请不要试图纠正。 谢谢。
【问题讨论】:
-
您能否发布您迄今为止在 Python 中尝试过的内容以及您在 Python 代码中遇到问题的地方
-
欢迎来到 SO!请使用tour 并阅读minimal reproducible example。请注意,SO 不是代码编写服务。
标签: python python-3.x matrix multidimensional-array input