python programming

 completed file required

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

 

.py file. 

 

strict deadline. by midnight(EST)

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

ISTA

1

3

0: Homework 3

Due June 7 at 11:59pm

1. (

2

pt.) Write some code that asks a user how old they are, then wishes them “Happy Birthday”
for every birthday they’ve had, with a counter to keep track.

Example output:

How old are you?

5

Oh, I missed all your birthdays! I’ll make it up now.

Happy Birthday 1

Happy Birthday 2

Happy Birthday 3

Happy Birthday

4

Happy Birthday 5

2. (2 pt.) You are given a large spreadsheet with two columns that represent the score for two
basketball teams in a game. You don’t care what the score was, only which team won. Write
a function that takes two scores, and returns a number: 1 if the first team won, 2 if the second
team won, and 0 if the game was a tie.

3. (2 pt.) Create a function that converts miles to inches. Then create a function that converts
inches to centimeters. Then create a function that converts centimeters to kilometers. Finally,
write a line of code that uses these three functions together to convert miles to kilometers.

4. (2 pt.) Write a function called convert miles that takes a single parameter representing
distance in miles. The function does the following:

(a) calculates the distance in inches

(b) calculates the distance in kilometers

(c) calculates the distance in furlongs

(d) prints the three values:

>>> convert_miles(47.0)

2977920 inches

75.63916800000001 kilometers

5.875 furlongs

1

5. (2 pt.) Write a function called in order that takes three numbers as parameters, and returns
True or False based on whether the numbers are in ascending order:

>>> in_order(3,6,9)

True

>>> in_order(3,9,6)

False

Here is a function that checks whether a number is a perfect square:

def is_a_square(n):

numroot = math.sqrt(n)

return (numroot == int(numroot))

6. (2 pt.) Using the is a square function, write a look for squares function. This function
should take a single number, and check if all the numbers less than or equal to that are
squares. When it finds a square, it should print out a message:

>>> look_for_squares(16)

1 is a square!

4 is a square!

9 is a square!

16 is a square!

7. (2 pt.) Using the is a square function, write a count squares function. This function
should take a single number, count how many of the numbers less than or equal to that are
squares, and return the count.

>>> count_squares(16)

4

8. (3 pt.) Consider a simple interactive geometry program. This program can calculate the area
of a triangle, circle, or square. The program first asks the user what shape they want. Then,
it asks them for the relevant measurements (base and height, radius, or side length). It then
reports the area of the shape.

(Hint: you should get the value of π from the math library)

Example output:

What shape: triangle, circle, or square?

circle

What is the radius?

2.627

The area of your circle is:

21.680536167875474

2

1

  • What to turn in
  • Submit your hw03.py script to the Homework 1 Dropbox folder in D2L.

    Total Points: 15 points possible
    Extra Credit: 2 points possible

    (There are 17 total points on the assignment; question 3 is nominally extra credit)

    3

      What to turn in

    ISTA

    1

    3

    0: Lab 3

    June 5,

    2

    013

    1 Functions

    (2 pt.)

    � Create a new text file named lab03.py.

    � Write a function that, given the length of two sides of a triangle, finds the length of the third
    side. It should take two numbers as input, and return one number.

    Add some code outside of the function to let the user input the two numbers, and see the
    result.

    � Write a function called triangular number. A triangular number counts the number of
    objects that make up an equilateral triangle, like this:

    (Wikipedia)

    1

    The function should take an input describing which triangular number to calculate, and return
    the calculated triangular number. (Use a for loop, not a formula.)

    2 Conditionals

    (2 pt.)

    � Write a function called password check. It should take a string as a parameter. If the string
    is the same as the secret password (that you make up), it should print a success message.
    Otherwise, it should print a failed / wrong password message.

    � Write a function to tell you about the weather. It should take the temperature as a parameter.
    The function should print, “It is freezing or pleasant or boiling outside,” based on whether
    the temperature is below freezing, above boiling, or in the middle.

    3 Pygame Programs

    3.1 Install Pygame

    If you haven’t already insalled Pygame, go to http://pygame.org/download.shtml and download
    pygame-1.9.1.win32-py2.7.msi for Windows, or
    pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg for Mac.

    3.2 Try out a program

    On the Pygame website (http://pygame.org), find a game to try. Pick something that looks like
    it’s simple, but complete (looks like you could actually play it). You can browse projects by the
    keywords in the left sidebar, or by searching in the tiny search bar under the Pygame logo.

    Suggestions: It might be easiest to look for a familiar game, like Pac-Man, Mario, Tetris, or
    Zelda. Other genre suggestions (try searching for keywords like this on Pygame’s website) include
    tower defense, platformer, third-person shooter, real-time puzzle, space sidescroller, racing game,
    memory, …

    Download the program, and run it. Once you have a game that runs, write down in your lab
    file the name of the game, the URL, and a short description of the game.

    Now, it’s time to dig into the code. Open up the program’s source code in an editor, and see if
    you can understand how the code relates to the actual gameplay.

    Then, find a (small) example of each of these things in the code, and copy it into your lab file:

    � a for loop

    � an if statement

    � code that draws graphics on the screen

    Write a sentence or two about each of these code snippets describing what you think the code
    does. If you don’t completely understand, that’s ok, but try to find code that you can kind of figure
    out.

    2

    http://pygame.org/download.shtml

    http://pygame.org

    (6 pt.)

    Total Points: 10 points possible
    Extra Credit: 0 points possible

    3

    Still stressed from student homework?
    Get quality assistance from academic writers!

    Order your essay today and save 25% with the discount code LAVENDER