Earthquake in python assignment expert

Gwalior Fort is a popular tourist place in Gwalior, Madhya Pradesh. Everyday peoples registered to visit Fort as token provided based on first come basis. Everyday limited numbers of peoples are allowed to visit. The management selects a number A1 randomly every day and generates another number A2 as count of the total number of set bits (i.e., total no. of 1s) in binary representation of all numbers from 1 to A1. For example, A1=3 then A2=4 [1(01) +2(10) +3(11)]. So, write a python module CountBit.py to find A2 using A1. You need to import this module in main program. In main program define a function

G-T(n) which takes a number and return value as shown in example by calling the appropriate function implemented in CountBit.py module.

Example-1 : Input : 3 , Output : 4

Example-2 : Input : 7 , Output : 12

Friend and Enemy

A group of F friends went to a haunted house.Each member was given a shirt with a number on it ranging from 1 to F. As they entered the haunted house, one of them was kidnapped and an enemy joined them.But unfortunately, the enemy didn't wear the shirt with the same number as the kidnapped one, instead wore the same as some other person.Find the numbers on the shirts of the enemy and the kidnapped person.

Input

The input is a single line containing space-separated positive integers from 1 to F.

Output

The output should be a single line containing the shirt numbers of the enemy and kidnapped person separated by a space.

Explanation

The given array is 3 1 5 2 1.

In the range from 1 to 5, the number 1 has occured twice and 4 is the missing number. So, 1 belongs to the enemy's shirt, and 4 belongs to kidnapped.Hence, the output should be 1 4.

Sample Input1

3 1 5 2 1

Sample Output1

1 4

Sample Input2

1 2 2 4

Sample Output2

2 3

  • 29th Apr, 2022
  • 15:34 PM
import turtle, datetime

# copied from my lab 5 solution:
def teleport(t, x, y):
    """ Move the turtle to (x, y), ensuring that nothing is drawn along the
        way. Postcondition: the turtle's orientation and up/down state is the
        same as before.
    """
    # save the current pen state
    pen_was_down = t.isdown()
    
    # pick up pen, move to coordinates
    t.up()
    t.goto(x, y)
    
    # restore pen state
    if pen_was_down:
        t.down()

# copied from A4, with a couple slight modifications:
def turtle_setup(canv_width, canv_height):
    """ Set up the canvas and a turtle; return a turtle object in hidden
        state. The canvas has size canv_width by canv_height, with a
        coordinate system where (0,0) is in the center, and automatic
        re-drawing of the canvas is disabled. Set the background image to
        earth.png.
    """
    # create a turtle to color pixels with
    t = turtle.Turtle()
   
    # set the screen size, coordinate system, and color mode:
    screen = t.getscreen()
    screen.setup(canv_width, canv_height)
    turtle.colormode(255) # specify how colors are set: we'll use 0-255
    
    t.hideturtle() # hide the turtle triangle
    screen.tracer(0, 0) # turn off redrawing after each movement
    
    turtle.bgpic('earth.png') # set the background image
    turtle.update()
    return t

def parse_row(line):
    """ Parse a line of the csv file, returning a dict with keys
    for latitude, longitude, timestamp, and magnitude.
    Pre: line is an unprocessed string representing a line of the file.
    Post: the returned dict has the following keys with values according
          to the data in the given line of the file:
            "latitude" -> (float)
            "longitude" -> (float)
            "timestamp" -> (str)
            "magnitude" -> (float)
    """
    # the line has all the data separated by commas, so
    # split the line into its constituent numbers
    # to make it easy to access the latitude, longitude, timestamp, and magnitude values
    data = line.split(",")
    # create a dictionary
    quake_dictionary = {}
    #Populate the dictionary with the  keys and values for latitude, longitude, timestamp, magnitude
    quake_dictionary["latitude"] = float(data[0])
    quake_dictionary["longitude"] = float(data[1])
    quake_dictionary["timestamp"] = data[2]
    quake_dictionary["magnitude"] = float(data[3])
    # return the resulting dictionary
    return quake_dictionary

def main():
    """ Main function: plot a circle on a map for each earthquake """
    # we'll scale coordinates and canvas to be 720x360, double
    # the size of the range of lat/lon coordinates
    scale = 2.0
    
    # call turtle_setup to set up the canvas and get a turtle
    t = turtle_setup(scale * 360, scale * 180)
    
    # open earthquakes.csv for reading
    eq_file = open('earthquakes.csv', 'r')
     
    # make a list to store the earthquate dictionaries
    dicts = []
    # parse each line of the file using parse_row and add each returned
    # dictionary into the list (skip the headers on the first line!)
    for line in eq_file.readlines()[1:]:
        dicts.append(parse_row(line))
    # for each earthquake dictionary in the list:
    for dict in dicts:
        # if the magnitude is larger than 1.0:
        magnitude = dict['magnitude']
        if magnitude > 1.0:
            # draw a circle with radius equal to the magnitude
            # at (longitude * scale, latitude * scale).
            teleport(t, dict['longitude'] * scale, dict['latitude'] * scale)

            # (optional) color the circle by magnitude
            r = int((magnitude - 1) * 255 / 8)
            g = int((9 - magnitude) * 255 / 8)
            b = int((9 - magnitude) * 255 / 8)

            # (challenge) by date.
            # Looking at the data, you may notice that the
            # earthquakes in our dataset all happened in 2016.
            """
            dateStart = datetime.datetime(2016, 7, 1)
            date = datetime.datetime.strptime(dict['timestamp'], '%Y-%m-%d %H:%M:%S')
            delta = date - dateStart
            days = delta.days
            totalDays = 62
            r = int(days * 255 / totalDays)
            g = int((totalDays - days) * 255 / totalDays)
            b = int((totalDays - days) * 255 / totalDays)
            """

            t.pen(pencolor=(r, g, b), pensize=1)
            t.circle(magnitude)

    # update the screen so all the circles are drawn on the canvas
    turtle.update()
    input('Press a key')  # There must be a better way

if __name__ == "__main__":
    main()