从C++到Python的变化

2024-09-29 17:14:53 发布

您现在位置:Python中文网/ 问答频道 /正文

帮助我使用 非常感谢大家

int main()
{
    int W; cout<< "Nhap tong khoi luong: "; cin >> W;
    int n; cout << "Nhap so do vat: "; cin>> n;
    int weight[100], worth[100];
    for(int i = 1; i<= n; i++)
    {
        cout<< "Nhap weight[" << i <<"]:"; cin >> weight[i];
        cout<< "Nhap worth[" << i <<"]:"; cin >> worth[i];
    }
}

Tags: forsomaindointvatweightcout
1条回答
网友
1楼 · 发布于 2024-09-29 17:14:53

C++到Python的出现:

import sys

sys.stdout.write("Nhap tong khoi luong: ")
W=int(sys.stdin.readline())
sys.stdout.write("Nhap so do vat: ")
n=int(sys.stdin.readline())
weight=list()
worth=list()
for i in range(1,n+1):
    sys.stdout.write("Nhap weight["+str(i)+"]");
    weight.append(int(sys.stdin.readline()))
    sys.stdout.write("Nhap worth[" + str(i) + "]");
    worth.append(int(sys.stdin.readline()))

相关问题 更多 >

    热门问题