Project 1: Some Really Random Things Solution

$35.00 $30.80


In this project, you provide four Python functions that solve particular problems as outlined below. The problem-solving aspects of these are the same as the exercises at the ends of the labs so far. The only difference is that instead of typing your code in the web browser and executing it with shift-enter, you will type the code in your text editor application, save it to a file called, and execute it in the terminal application by typing “python ./” without quotes. All your functions should be in that single file. There are many ways to implement these functions. Your solutions must only employ features that we have introduced in lecture, lab, or in this specification. As a reminder, your work must be your own, and we watch for and respond to academic dishonesty.


  1. Write a function that takes as a parameter a positive integer hand prints an upside-down isosceles triangle of asterisks. Your function must be called print_isosceles(h), and must not return a value. For example, print_isosceles(5) should print












Notice that there is no leading space in front of the first line of asterisks.


  1. Write a function that takes as parameters three integers and computes and returns the median of the three. That is, for the three provided integers, return such that ≤ ≤. Your function must be called median_of_three(a,b,c), and must not print anything to screen. For example, median_of_three(7, -3, 0) should return 0, because −3 ≤ 0 ≤ 7.


  1. Typically, we consider the center of a circle to be it origin. Then, the coordinates of the center and the radius define the circle. Another way to define a circle that is commonly used in graphical programming libraries is by the coordinates of the upper left hand cornerof the smallest square that contains the circle, and providing the width of that square, which is equivalent to the diameter of the circle. Assume that coordinate 0,0 is the upper-left hand corner of the universe, and our coordinate system is relative to that point so that x coordinates increase to the right and y coordinates increase down.


Provide a function that takes as parameters origin_x and origin_y representing the coordinates of the upper left hand corner of the circle’s


bounding square, the diameter of the circle, and the x and y coordinates of a point somewhere in the same coordinate system. Your function should return True if the point is inside of the circle, and False otherwise. Your function must be called point_is_in_circle(origin_x, origin_y, diameter, x, y), and must not print anything to the screen. For example,


point_is_in_circle(5, 15, 100, 51, 90) should return True.


point_is_in_circle(5, 15, 100, 102, 91) should return Falce. In both cases, the upper left hand corner of the square is at x=5, y=15, and the diameter is 100. As you can see in the illustration below, the point x=52, y=61 in green is clearly inside of the circle. Likewise, the point x=102, y=91 in red is clearly outside of the circle.




0,0 (provided)















False 100px









  1. To use a function that is provided by Python, but not in the __main__namespace (where we have been working so far), we use the import The statement


from random import randint


imports the function randint from the random library for use in your program. Typically (and in this project), we place all import lines at the top of the file, at the left margin.


The randint function takes two parameters and and returns an integer between and , inclusive so ≤ ≤ . Using the randint function, write a function that simulates a Pokéstop by returning items (represented as these exact strings) with the following probabilities:


‘Poke Ball’ 57.6%
‘Great Ball’ 11.1%
‘Potion’ 7.6%
‘Razz Berry’ 7.5%
‘Revive’ 7.4%
‘Super Potion’ 3.1%
‘Ultra Ball’ 2.9%
‘Hyper Potion’ 1.5%
‘Max Potion’ 0.8%
‘Egg’ 0.42%
‘Max Revive’ 0.08%


Your function must be called pokestop(), and must not print anything to the screen. For example,


pokestop() should return the string ‘Razz Berry’ around 75 out of every 1000 calls.


10% Bonus Opportunity


Successful, well-presented implementations of the above functions will receive full credit. For a bonus, replace the test invocations of your function with a loop that implements a menu system. Each time the loop runs, it should prompt the user with the choices of functions, and numbers or letters to select each. Upon selection of a function, the loop should prompt the user for the values of each parameter (if any are needed) and then call the specified function with the provided parameters, print any returned results, and cycle to the menu again. The last option on the menu should be to exit the program. If the user selects that option, change the value of the control variable in your while loop so that it is False. This will terminate the loop and your program will exit.


One important note is that your menu system must only prompt the user for actions and call the appropriate functions based on her selections. The functions always exist, whether they are called or not. Do not define functions conditionally; although Python supports this, we do not employ that feature in our introductory curriculum.




YourName.pdf: A brief writeup that details what you found easy, challenging, or difficult about this project and how you overcame those issues. Also discuss how you tested each of your functions to ensure their correctness. A single Python file containing your four implementations and optionally the while-loop driven menu system. The four functions must be called






point_is_in_circle(origin_x, origin_y, diameter, x, y), and pokestop().


Each function should either return a value or print to screen as specified, but never both. These four functions and the __main__ conditional are the only things that should begin on the far left margin of your code. Do not change the definitions of the functions in the skeleton file. Only replace pass lines with your implementations.


We have provided a unit test file for you to apply. This does not test functionality, but does ensure that your submission will be runnable in our framework. These unit tests work already with the skeleton file provided. If the provided unit tests fail to work on the file you submit, you will receive no credit for this assignment.