Giter Site home page Giter Site logo

gizmo's Introduction

Can you speak Python?

This is a Python challenge. Create pull requests (PR's) to this repository to solve it. Upon PR submission, the GitHub action robots will check your code and report back how well you did. You can then add more commits to your PR until all tests come back green, which means you win!

The exercises are meant to test your knowledge of some important features of the Python programming language. When it's not immediately obvious to you how to solve an exercise using only a few lines of code, it is likely you can learn a new Python trick by checking the links below the exercise.

Exercise 1: Make a pull request

  1. Fork this repository
  2. Create a new branch (name it whatever you like)
  3. Add a new file gizmo.py to the repository
  4. Create a pull-request from your new branch to the master branch of this repository

When gizmo.py exists, there should be gizmo python module that you can import.

For example:

>>> import gizmo

Learn how to fork, branch and submit a pull request
Learn how to create a Python module

Exercise 2: Create a function

Add a hello() function to the gizmo module. The function should take two parameters: name and country. The country parameter is optional and should default to 'Finland'. When called, the function uses the print() function to write the text Hello {name}, how are things in {country}? to the screen, where {name} and {country} should be the name and country given as parameters.

For example:

>>> import gizmo
>>> gizmo.hello('Gizmo', 'Germany')
Hello Gizmo, how are things in Germany?
>>> gizmo.hello('Gizmo')
Hello Gizmo, how are things in Finland?

Learn how to define functions in Python

Exercise 3: Use a loop

Add a spell() function to the gizmo module that uses the print() function to spell out the word given as a parameter to the function, with dots between the letters. Use a for-loop to implement this (no split/join).

For example:

>>> import gizmo
>>> gizmo.spell('hello')
h.e.l.l.o

Learn how to write a for loop in Python

Exercise 4: Use string formatting

Reading a bunch of files with only small differences in their filenames is a very common occurrence in any research code. Add a function relative_path() to the gizmo module that returns a list of files, including their relative path, following the following pattern:

'./subjects/mock_recording_{subject_identifier}.rec'

where {subject_identifier} is any string. Subject identifiers will be passed to the function as a list of strings.

For example:

>>> import gizmo
>>> subject_identifiers = ['subject1', 'subject2']
>>> names = gizmo.relative_path(subject_identifiers)
>>> print(names)
['./subjects/mock_recording_subject1.rec', './subjects/mock_recording_subject2.rec']

Get started with string formatting
If you want to go into more detail you can also check the python documentation here.

Exercise 5: Create a Class

Add a class called Gizmo to your gizmo.py module.

For example:

>>> from gizmo import Gizmo
>>> g = Gizmo()

Learn how to create a Python class

Exercise 6: Add an attribute to your class

Modify your class such that when you create a new instance of Gizmo, you can give it a name. The name is a string. Afterwards, the name should be available as the .name attribute.

For example:

>>> from gizmo import Gizmo
>>> g = Gizmo('Ariel')
>>> g.name
'Ariel'

Learn how to add attributes

Exercise 7: Add a method to your class

Modify your class such that it has a .speak() method. Calling this method will make the Gizmo object print its name using the print() function.

For example:

>>> from gizmo import Gizmo
>>> g = Gizmo('Ariel')
>>> g.speak()
Ariel

Learn how to add methods to your class

Exercise 8: Build a generator

Add a function generate_fibonacci_sequence(n) to your gizmo module that will be a generator that yields the first n numbers of the Fibonacci sequence.

For example:

>>> import gizmo
>>> fib = gizmo.generate_fibonacci_sequence(5)
>>> while(True):
>>>     print(next(fib))
0
1
1
2
3
StopIteration

Learn about Python generators

Exercise 9: Document your function using numpydoc

Add a docstring to the multiplication_table function. Use the "numpydoc" style for this documentation. The documentation should contain:

  1. Short summary: a one-line description of what the function does.
  2. Extended summary: A longer description with more details about what the function does.
  3. Parameters: a list of all parameters that the function takes. For each parameter, describe:
    1. The parameter name
    2. Its expected type (int, bool, str, array, ...)
    3. What the parameter does
  4. Returns: a list of all values returned by the function. For each return value, describe:
    1. The returned value's name
    2. Its type (int, bool, str, array, ...)
    3. What the returned value means

Learn about docstrings
Learn about the numpydoc documentation style

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.