GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

could some one change the code in ptyhon

import java.util.Scanner;

public class Mily {
 
    public static int summation(int i) {
        return (i * (i + 1)) / 2;
    }
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int T = sc.nextInt();
        int[] array = new int[T];
        for (int i = 0; i < T; i++)
            array[i] = sc.nextInt();
        for (int i : array) {
            int temp = ((int) Math.ceil((Math.sqrt((1 + (8 * i))) - 1) / 2));
            int summation = summation(temp);
            while (summation % 2 != i % 2) {
                temp++;
                summation += temp;
            }
            System.out.println(temp);
        }
        sc.close();
    }
}

 

asked Feb 16, 2017 by anonymous

1 Answer

"""Python is a functional programming language. We can write the code similar to C"""
def summationOfNumber(num):
    return (num * (num + 1)) / 2
    
summation = 0    
#n python, array is dynamic.So there is no need of new operator
array = []

#comment given line when you use  python 2 #
T = int(raw_input())


#For Python 3,uncomment following line
#T = int(input())


for i in range(0,T):

    #comment given line when you use python 2 #
    number = int(raw_input())

    #For Python 3,uncomment following line
    #number = int(input())

    array.append(number)

for i in array:
    temp = int( math.ceil((math.sqrt((1 + (8 * i))) - 1) / 2))
    summation = summationOfNumber(temp)
    while (summation % 2 != i %2):
        temp += 1
        summation += temp
        

print summation

answered Feb 21, 2017 by sachin261
...