【发布时间】:2014-11-12 17:48:11
【问题描述】:
在 C++ 中,我有下面的代码,我想在 Python 中做同样的代码。
#include iostream
using namespace std;
int main()
{
int tab[10][10], m, n, i, j;
cout << "\n number of rows n = ";
cin >> n;
cout << "\n number of columns m = ";
cin >>m;
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
{
cout << "\n tab[" << i << "][" << j << "] = ";
cin >> tab[i][j];
}
}
cout << endl;
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
cout << "\t\t" << tab[i][j];
cout << "\n\n";
}
return 0;
}
我试过这个:
def main():
pass
tab = []
m = input ("Numbers of rows: ")
n = input ("Numbers of columns: ")
for i in xrange(m):
for j in xrange(n):
print tab[i:j], "= "
arr = input ("tab[i:j]")
print arr
我不知道在 for 循环中打印 tab[i][j] = "value input from keyboard"
【问题讨论】:
-
到目前为止你尝试过什么?
-
堆栈溢出不是代码翻译服务。
-
用python写这段代码真的很简单,大功告成!
-
cout和cin是 C++ 结构,在 Python 中没有等价物,因为 Pyhton 是一种高级语言。 -
您是否也想包含缓冲区溢出错误?这在 Python 中可能有点困难。