Friday, February 1, 2019

SUM OF THE SERIES

  • Problem Description

    Write a program to find sum of series
    Hint:1+2+3+4+n
  • CODING ARENA::
  • a=int(input())
    sum=0
    for i in range(1,a+1):
        sum=sum+i
    print(sum)
  • Test Case 1

    Input (stdin)
    18
    
    
    Expected Output
    171
  • Test Case 2

    Input (stdin)
    100
    
    
    Expected Output
    5050

The Castle Gate

  • Problem Description

    Gudi, a fun loving girl from the city of Dun, travels to Azkahar - a strange land beyond the mountains. She arrives at the gates of Castle Grey, owned by Puchi,the lord of Azkahar to claim the treasure that it guards. However, destiny has other plans for her as she has to move through floors, crossing obstacles on her way to reach the treasure.
    The gates of the castle are closed. An integer N is engraved on the gates. A writing on the wall says
    Tap the gates as many times as there are unordered pairs of distinct integers from 1 to N whose bit-wise XOR does not exceed N
    Help her find the number of the times she has to tap.

    Input:
    First line contains an integer T
    T testcases follow.
    Each testcase consists of an integer N

    Output:
    Print the answer to each testcase in a newline.


    Explanation
    For N=4, pairs are (1,2) , (1,3) and (2,3)
  • CODING ARENA
  • def ans():
        for _ in range(int(input())):
            n=int(input())
            if(n<3):
                yield 0
            else:
                    m=1<<(n.bit_length()-1)
                    yield ((m-1)*(m-2)+3*(n-m+1)*(n-m))//2
    print(*ans(),sep="\n")
  • Test Case 1

    Input (stdin)
    3
    
    4
    
    6
    
    8
    
    
    Expected Output
    3
    
    12
    
    21
  • Test Case 2

    Input (stdin)
    5
    
    6
    
    10
    
    20
    
    26
    
    12
    
    
    Expected Output
    12
    
    30
    
    135
    
    270
    
    51

Day Old Bread

  • Problem Description

    A bakery sells loaves of bread for 185 rupees each. Day old bread is discounted by 60 percent. Write a program that begins by reading the number of loaves of day old bread being purchased from the user. 

    Then your program should display the regular price for the bread, the discount because it is a day old, and the total price. 

    All of the values should be displayed using two decimal places, and the decimal points in all of the numbers should be aligned when reasonable values are entered by the user.
  • CODING ARENA
  • a=int(input())
    b=a*185
    print("Loaves Discount")
    print("Regular Price",b)
    print("Total Discount",b*.6)
    print("Total Amount to be paid",b-(b*.6))
  • Test Case 1

    Input (stdin)
    15
    
    
    Expected Output
    Loaves Discount
    
    Regular Price 2775
    
    Total Discount 1665.0
    
    Total Amount to be paid 1110.0
  • Test Case 2

    Input (stdin)
    25
    
    
    Expected Output
    Loaves Discount
    
    Regular Price 4625
    
    Total Discount 2775.0
    
    Total Amount to be paid 1850.0

Body Mass Index

  • Problem Description

    Write a program that computes the body mass index (BMI) of an individual. 

    Your program should begin by reading a height and weight from the user. If you read the height in meters and the weight in kilograms then body mass index is computed using this slightly simpler formula:

    BMI = weight / height *height

    Use round function in the final output value
  • CODING ARENA
  • a=float(input())
    b=int(input())
    c=b/(a*a)
    print("The BMI IS",round(c,2))
  • Test Case 1

    Input (stdin)
    1.69
    
    64
    
    
    Expected Output
    The BMI IS 22.41
  • Test Case 2

    Input (stdin)
    1.72
    
    71
    
    
    Expected Output
    The BMI IS 24.0

Area of a Room

  • Problem Description

    Write a program that asks the user to enter the width and length of a room. 

    Once the values have been read, your program should compute and display the area of the room. 

    The length and the width will be entered as floating point numbers. Include units in your prompt and output message; either feet or meters, depending on which unit you are more comfortable working with.

    Formula = length*width
  • CODING ARENA
  • a=float(input())
    b=float(input())
    c=a*b
    print("The area of the room is",round(c,2),"square feet")
  • Test Case 1

    Input (stdin)
    23.44
    
    22.33
    
    
    Expected Output
    The area of the room is 523.42 square feet
  • Test Case 2

    Input (stdin)
    18.66
    
    22.45
    
    
    Expected Output
    The area of the room is 418.92 square feet

Three Idiots

  • Problem Description

    Create a program that reads three integers from the user and displays them in sorted order (from smallest to largest). 

    Use the min and max functions to find the smallest and largest values. 

    The middle value can be found by computing the sum of all three values, and then subtracting the minimum value and the maximum value.
  • CODING ARENA
  • a=[]
    for i in range(3):
        b=int(input())
        a.append(b)
    a.sort()
    print("The minimum value is",a[0])
    print("The maximum value is",a[2])
    print("The middle value is",a[1])
  • Test Case 1

    Input (stdin)
    25
    
    12
    
    1988
    
    
    Expected Output
    The minimum value is 12
    
    The maximum value is 1988
    
    The middle value is 25
  • Test Case 2

    Input (stdin)
    9
    
    19
    
    1972
    
    
    Expected Output
    The minimum value is 9
    
    The maximum value is 1972
    
    The middle value is 19

Convert integer to float

  • Problem Description

    Given an input as integer to the machine , he need to get the output of corresponding floating point number

    Hint: Divide the number by 100 and display the output

    Please help him to write the program that satisfy the output.
  • CODING ARENA
  • a=int(input())

    b=a/100
    print(b)
  • Test Case 1

    Input (stdin)
    12
    
    
    Expected Output
    0.12
  • Test Case 2

    Input (stdin)
    15
    
    
    Expected Output
    0.15

Gravity Fall

  • Problem Description

    Create a program that determines how quickly an object is traveling when it hits the ground. The user will enter the height from which the object is dropped in meters (m).

    Because the object is dropped its initial speed is 0m/s. Assume that the acceleration due to gravity is 9.8m/s. 

    vf =squareroot(vi+2ad) 

    You can use the formula given above to compute the final speed, vf , when the initial speed, vi , acceleration, a, and distance, d, are known
  • CODING ARENA
  • import math
    a=int(input())
    ans=math.sqrt(2*9.8*a)
    print("The object will hit the ground at",round(ans,2),"m/s")

  • Test Case 1

    Input (stdin)
    45
    
    
    Expected Output
    The object will hit the ground at 29.7 m/s
  • Test Case 2

    Input (stdin)
    148
    
    
    Expected Output
    The object will hit the ground at 53.86 m/s

eLab Petrol Bunk

  • Problem Description

    In the United States, fuel efficiency for vehicles is normally expressed in miles-pergallon (MPG).

    In Canada, fuel efficiency is normally expressed in liters-per-hundred kilometers (L/100 km). 

    Use your research skills to determine how to convert from MPG to L/100 km. 

    Then create a program that reads a value from the user in American units and displays the equivalent fuel efficiency in Canadian units.

    Note:

    Formula is --> 282.48 / fuel efficiency in MPG.
  • CODING ARENA
  • a=int(input())
    b=282.48/a
    print(round(b,2))
  • Test Case 1

    Input (stdin)
    24
    
    
    Expected Output
    11.77
  • Test Case 2

    Input (stdin)
    25
    
    
    Expected Output
    11.3

Multiplication Table

  • Problem Description

    Write a python program to print the table of a given number 

    Print the multiplication till 10.
  • CODING ARENA
  • n=int(input())
    for i in range(1,11):
        print(n,"x",i,"=",n*i)
  • Test Case 1

    Input (stdin)
    7
    
    
    Expected Output
    7 x 1 = 7
    
    7 x 2 = 14
    
    7 x 3 = 21
    
    7 x 4 = 28
    
    7 x 5 = 35
    
    7 x 6 = 42
    
    7 x 7 = 49
    
    7 x 8 = 56
    
    7 x 9 = 63
    
    7 x 10 = 70
  • Test Case 2

    Input (stdin)
    17
    
    
    Expected Output
    17 x 1 = 17
    
    17 x 2 = 34
    
    17 x 3 = 51
    
    17 x 4 = 68
    
    17 x 5 = 85
    
    17 x 6 = 102
    
    17 x 7 = 119
    
    17 x 8 = 136
    
    17 x 9 = 153
    
    17 x 10 = 170

Note To Frequency - A NOTE

  • Problem Description

    The following table lists an octave of music notes, beginning with middle A, along with their frequencies.

    Note Frequency (Hz) 

    A4 440.00

    Begin by writing a program that reads the name of a note from the user and displays the notes frequency. Your program should support all of the notes listed previously.

    Once you have your program working correctly for the notes listed previously you should add support for all of the notes from A0 to A8. 

    While this could be done by adding many additional cases to your if statement, such a solution is cumbersome,
    inelegant and unacceptable for the purposes of this exercise. Instead, you should exploit the relationship between notes in adjacent octaves. In particular, the frequency of any note in octave n is half the frequency of the corresponding note in octave n+1.

    By using this relationship, you should be able to add support for the additional notes without adding additional cases to your if statement.


    Hint: To complete this exercise you will need to extract individual characters from the two-character note name so that you can work with the letter and the octave number separately. 

    Once you have separated the parts, compute the frequency of the note in the fourth octave using the data in the table above. 

    Then divide the frequency by 2 power(4-x ), where x is the octave number entered by the user. This will halve or double the frequency the correct number of times.

    Then divide the frequency by 2 power(4-x ), where x is the octave number entered by the user. (freq=freq/2**(4-octave))
  • CODING ARENA
  • a=input()
    b=int(a[1])
    print(440//(2**(4-b)))
  • Test Case 1

    Input (stdin)
    A2
    
    
    Expected Output
    110
  • Test Case 2

    Input (stdin)
    A8
    
    
    Expected Output
    7040

Grade

  • Problem Description

    Write a program asks the user to enter a exam score, and then prints the grade (A/B/C/D) that corresponds to the score. 

    If the score that the user entered is less than 0 or greater than 100, the program prints an error message.
    Use the following grades
    A grade >=85
    B grade 70-85
    C grade 50-70
    D grade <50

    Mandatory:

    Use if and elif
  • CODING ARENA
  • a=int(input())
    if(a>=85 and a<=100):
        print("A")
    elif(a>=70 and a<85):
        print("B")
    elif(a>=50 and a<70):
        print("C")
    else:
        print("D")
  • Test Case 1

    Input (stdin)
    85
    
    
    Expected Output
    A
  • Test Case 2

    Input (stdin)
    78
    
    
    Expected Output
    B

Richter Scale

  • Problem Description

    The following table contains earthquake magnitude ranges on the Richter scale and their descriptors:

    Magnitude Descriptor

    Less than 2.0 Micro
    2.0 to less than 3.0 Very minor
    3.0 to less than 4.0 Minor
    4.0 to less than 5.0 Light
    5.0 to less than 6.0 Moderate
    6.0 to less than 7.0 Strong
    7.0 to less than 8.0 Major
    8.0 to less than 10.0 Great
    10.0 or more Meteoric

    Write a program that reads amagnitude from the user and displays the appropriate descriptor as part of a meaningful message. For example, if the user enters 5.5 then your program should indicate that a magnitude 5.5 earthquake is considered to be a moderate earthquake

    Mandatory:

    Use if and elif
  • CODING ARENA
  • a=float(input())
    if(a<2.0):
        print("Micro")
    elif(a>=2.0 and a<3.0):
        print("Very minor")
    elif(a>=3.0 and a<4.0):
        print("Minor")
    elif(a>=4.0 and a<5.0):
        print("Light")
    elif(a>=5.0 and a<6.0):
        print("Moderate")
    elif(a>=6.0 and a<7.0):
        print("Strong")
    elif(a>=7.0 and a<8.0):
        print("Major")
    elif(a>=8.0 and a<10.0):
        print("Great")
    else:
        print("Meteoric")

  • Test Case 1

    Input (stdin)
    7.9
    
    
    Expected Output
    Major
  • Test Case 2

    Input (stdin)
    8
    
    
    Expected Output
    Great

Note To Frequency - F NOTE

  • Problem Description

    The following table lists an octave of music notes, beginning with middle F, along with their frequencies. 

    Note Frequency (Hz) F4 349.63

    Begin by writing a program that reads the name of a note from the user and displays the notes frequency. Your program should support all of the notes listed previously.

    Once you have your program working correctly for the notes listed previously you should add support for all of the notes from F0 to F8. While this could be done by adding many additional cases to your if statement, such a solution is cumbersome,
    inelegant and unacceptable for the purposes of this exercise. 

    Instead, you should exploit the relationship between notes in adjacent octaves. In particular, the frequency of any note in octave n is half the frequency of the corresponding note in octave n+1.

    By using this relationship, you should be able to add support for the additional notes without adding additional cases to your if statement.

    Hint: 

    To complete this exercise you will need to extract individual characters from the two-character note name so that you can work with the letter and the octave number separately. 

    Once you have separated the parts, compute the frequency of the note in the fourth octave using the data in the table above.
    Then divide the frequency by 2 power(4-x ), where x is the octave number entered by the user. 

    Then divide the frequency by 2 power(4-x ), where x is the octave number entered by the user. (freq=freq/2**(4-octave))

    This will halve or double the frequency the correct number of times.
  • CODING ARENA
  • a=input()
    b=int(a[1])
    print(round(349.63/(2**(4-b)),4))
  • Test Case 1

    Input (stdin)
    F7
    
    
    Expected Output
    2797.04
  • Test Case 2

    Input (stdin)
    F2
    
    
    Expected Output
    87.4075

Indian Zodiac

  • Problem Description

    The Indian zodiac assigns animals to years in a 12 year cycle. One 12 year cycle is shown in the table below. The pattern repeats from there, with 2012 being another year of the dragon, and 1999 being another year of the hare. 

    2000 Dragon
    2001 Snake
    2002 Horse
    2003 Sheep
    2004 Monkey
    2005 Rooster
    2006 Dog
    2007 Pig
    2008 Rat
    2009 Ox
    2010 Tiger
    2011 Hare 

    Write a program that reads a year from the user and displays the animal associated with that year. Your program should work correctly for any year greater than or equal to zero, not just the ones listed in the table.


    Mandatory:

    Use if and elif
  • CODING ARENA
  • year = int(input())
    if (year - 2000) % 12 == 0:
        sign = 'Dragon'
    elif (year - 2000) % 12 == 1:
        sign = 'Snake'
    elif (year - 2000) % 12 == 2:
        sign = 'Horse'
    elif (year - 2000) % 12 == 3:
        sign = 'sheep'
    elif (year - 2000) % 12 == 4:
        sign = 'Monkey'
    elif (year - 2000) % 12 == 5:
        sign = 'Rooster'
    elif (year - 2000) % 12 == 6:
        sign = 'Dog'
    elif (year - 2000) % 12 == 7:
        sign = 'Pig'
    elif (year - 2000) % 12 == 8:
        sign = 'Rat'
    elif (year - 2000) % 12 == 9:
        sign = 'Ox'
    elif (year - 2000) % 12 == 10:
        sign = 'Tiger'
    else:
        sign = 'Hare'

    print(sign)


                                                                                     
  • Test Case 1

    Input (stdin)
    1998
    
    
    Expected Output
    Tiger
  • Test Case 2

    Input (stdin)
    2017
    
    
    Expected Output
    Rooster