• Python Revision Part 1

    Write output for the following python codes.

    numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)   
    num_sum = 0  
    count = 0  
    for x in numbers:  
        num_sum = num_sum + x  
        count = count + 1   
        if count == 5:  
            break  
    print("Sum of first ",count,"integers is : ", num_sum)


    for x in range(6):  
        if (x == 3 or x==6):  
            continue  
        print(x) 


    def avg_number(x, y):  
        print("Average of ",x," and ",y, " is ",(x+y)/2)  
    avg_number(3, 4)


    def nsquare(x, y):  
        return (x*x + 2*x*y + y*y)  
    print("The square of the sum of 2 and 3 is : ", nsquare(2, 3))


    def nsquare(x, y = 2):  
        return (x*x + 2*x*y + y*y)  
    print("The square of the sum of 2 and 3 is : ", nsquare(2))  
    print("The square of the sum of 2 and 3 is : ", nsquare(2,4))


    def marks(english, math = 85, science = 80):  
        print('Marks in : English is – ', english,', Math – ',math, ', Science – ',science)  
    marks(71, 77)  
    marks(65, science = 74)  
    marks(science = 70, math = 90, english = 75)
     

    You may also like...