question

Mkenzhe-7476 avatar image
0 Votes"
Mkenzhe-7476 asked VickyKumarMindtreeConsultingPVTLTD-5545 answered

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

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-profile
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

VickyKumarMindtreeConsultingPVTLTD-5545 avatar image
0 Votes"
VickyKumarMindtreeConsultingPVTLTD-5545 answered

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 ?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.