C# code convert to Python. Hello Guys, can anyone help me to convert below C# code to Python. thanks

Mkenzhe 1 Reputation point
2022-02-26T12:14:56.203+00:00

static void Main(string[] args)
{
const int count = 26;
int[] ch1 = new int[count];
int[] ch2 = new int[count];

        for (int i = 0; i < ch1.Length; i++)
        {
            ch1[i] = 1;
        }
        for (int i = 0; i < ch2.Length; i++)
        {
            ch2[i] = 1;
        }

        Console.WriteLine(ch1.Sum() + ch2.Sum());
        Console.ReadKey();
    }
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,896 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,156 Reputation points Microsoft Employee
    2022-03-02T10:47:24.823+00:00

    Hi
    If I understood correct , you want to create 2 array of length 26 and assigned the value 1 individually in array ch1 and ch2 , and you want to sum all the element of array and then add both array , right?

    Equivalent Python code:

    from array import *
    ch1 =array('i',[])
    ch2 =array('i',[])

    for i in range(26)
    ch1.append(1)

    for i in range(26)
    ch2.append(1)

    print(sum(ch1)+sum(ch2))

    Let me know if you have any doubt ?

    0 comments No comments