Friday, February 1, 2019

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

Noise Levels

  • Problem Description

    The following table lists the sound level in decibels for several common noises.Noise Decibel level (dB),

    Jackhammer 130
    Gas lawnmower 106
    Alarm clock 70
    Quiet room 40 

    Write a program that reads a sound level in decibels from the user. 

    If the user enters a decibel level that matches one of the noises in the table then your program should display a message containing only that noise. 

    If the user enters a number of decibels between the noises listed then your program should display a message indicating which noises the level is between. 

    Ensure that your program also generates reasonable output for a value smaller than the quietest noise in the table, and for a value larger than the loudest noise in the table.

    Note:
    Use only if and elif
  • CODING ARENA
  • a=int(input())
    if(a>=130):
        print("Jackhammer")
    elif(a>=106 and a<130):
        print("Gas lawnmower")
    elif(a>=70 and a<106):
        print("Alarm clock")
    elif(a>=40 and a<70):
        print("Quiet room")
    else:
        print("******")

  • Test Case 1

    Input (stdin)
    130
    
    
    Expected Output
    Jackhammer
  • Test Case 2

    Input (stdin)
    106
    
    
    Expected Output
    Gas lawnmower

India Vs England 50-50 Match

  • Problem Description

    Virat Kohli has won the toss against England in a 50 Over World Cup Final 2019. During the Toss time the commentator have him a funny task to test his mathematical skills. 

    Shastri was the umpire to judge his mathematical skills. When the number is 28 he needs tell "INDIA" and when the number is 25 he needs to tell "ENGLAND".

    Refer sample Input and Output:
    Input 1: 20 Output: INDIA
    Input 2: 21 Output: ENGLAND
    Input 3: 22 Output: INDIA

  • CODING ARENA
  • a=int(input())
    if(a%2==0):
        print("INDIA")
    else:
        print("ENGLAND")
  • Test Case 1

    Input (stdin)
    20
    
    
    Expected Output
    INDIA
  • Test Case 2

    Input (stdin)
    21
    
    
    Expected Output
    ENGLAND