Git Product home page Git Product logo

quiz-itp-w2's Introduction

Intro to Python - Quiz - Week 2

This small quiz is just for validating the concepts covered during the first week of our course. It's not something you can pass or fail. We use the results of this quiz to evaluate if we need to add more support sessions or improve any aspect of the course.

PLEASE, don't cheat. Make it honest. We'll never share the data with the rest of the class.

To complete this quiz, fork the repo, work on the questions under quiz-questions/ and submit a Pull Request

Question 1

Take a look at the following code and answer:

a = 10
b = 3
c = 7


def test_scope(b):
    a = 11
    return a + b + c

c = c + test_scope(5)

What will be the final value of the variable c?

Options:
a) 23
b) 30
c) 29
d) 28
e) None  # The function gets into an infinite loop

IMPORTANT: Return the actual value as shown in the options. DO NOT surround it with quotes. Example, if you think that 23 is the correct answer, you should put return 23. Again, DON'T use quotes, and DON'T use the option number (return a, return "a)", return "a", etc).

Question 2

Write a function number_of_customers_per_state that receives a dictionary containing states (as keys) and customers for those states (as a list of dictionaries) and returns a final dictionary containing the count of customers per state.

Example:

customers = {
    'UT': [{
        'name': 'Mary',
        'age': 28
    }, {
        'name': 'John',  # Eldest
        'age': 31
    }],
    'NY': [{
        'name': 'Linda',  # Eldest
        'age': 71
    }]
}
number_of_customers_per_state(customers)

Should return:

{
    'UT': 2,
    'NY': 1
}

Question 3

Write a function eldest_customer_per_state that receives a dictionary containing states (as keys) and customers for those states (as a list of dictionaries) and returns a final dictionary containing the eldest customer per each state.

Example:

customers = {
    'UT': [{
        'name': 'Mary',
        'age': 28
    }, {
        'name': 'John',  # Eldest
        'age': 31
    }],
    'NY': [{
        'name': 'Linda',  # Eldest
        'age': 71
    }, {
        'name': 'Lisa',
        'age': 25
    }]
}
eldest_customer_per_state(customers)

Should return:

{
    'UT': {
        'name': 'John',
        'age': 31
    },
    'NY': {
        'name': 'Linda',
        'age': 71
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.