Git Product home page Git Product logo

pypart2's Introduction

Part 2

Accompanying resources

Exercise 1

Using the Python interpreter:

  • Define a function called greet that meets the following criteria:
    • Takes an argument called name.
    • Prints a greeting using the name parameter.
  • Invoke the greet function using your name as the argument.
  • Invoke the greet function using the value "Darth Vader" as the argument.
  • Invoke the greet function using the value "Guido van Rossum" as the argument.

Exercise 2

Create a script called greet.py.

  • Define a function called greet that meets the following criteria:
    • Takes an argument called name.
    • Prints a greeting using the name parameter.
  • Define another function called name_input that meets the following criteria:
    • Takes no arguments.
    • Prints a message to the screen requesting the user to provide a name.
    • Returns a string with the value equals to that of the provided name.
  • Using these two functions, prompt the user for a name and print it to the screen.
  • Each function must have an appropriate docstring.

Exercise 3

Create a script called exponentiator.py

  • Define a function named exponentiate with the following criteria:

    • Takes two integers as arguments.
    • Returns the value of the first integer raised to the power of the second integer.
    • Make sure the function has an appropriate docstring.
  • Define a function named raise_to_fourth_power with the following criteria:

    • Takes one integer as an argument.
    • Calls the exponentiate function to raise the given paremeter to the 4th power.
    • Make sure the function has an appropriate docstring.
  • Create a variable called square. The value assigned to this variable should be a lambda expression that utilizes the exponentiate function to raise a number to the power of 2.

  • Create a variable called cube. The value assigned to this variable should be a lambda expression that utilizes the exponentiate function to raise a number to the power of 3.

  • In the main part of your script, print the output of square(2).

  • In the main part of your script, print the output of cube(2).

  • In the main part of your script, print the output of raise_to_fourth_power(2).

  • When executed, your script should provide the following output.

4
8
16

pypart2's People

Contributors

nikkiwojo avatar xt0fer avatar

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.