Trux Falsy
Complete generations 0, 1, and 2 of Trux Falsy. By default Trux Falsy uses the C programming language syntax. To change it to Python before starting, click the gear in the upper right corner and choose "and or not True False".
Challenge
Complete the game!
Min 3
Write the function min_3(number_1, number_2,
number_3)
that returns the minimum of the 3 parameters to
the function, number_1
, number_2
,
number_3
. The function should not use the
built-in min
function. The function is
the same as the min_3
function you previously
wrote. This version of it should use logical operators to
simplify the code.
Test Cases
print('Input:', ?, ',', ?, ',', ?, '\tActual:', min_3(?, ?, ?), '\tExpected:', ?)
Single Digit
Write the function is_single_digit(integer)
that
returns True
if the parameter integer is a
single digit number and returns False
otherwise.
Note, the function should not use any conditional
statemetns.
Test Cases
print('Input:', ?, '\tActual:', is_single_digit(?), '\tExpected:', ?)
Point in Rectangle
Computer animations where different elements interact, requires being able to tell if two elements overlap. There are many different ways to determine whether two entities are colliding. One of them involves circles, similar to the point in circle program from last class. Another, is determining if a point is located within a rectangle.
Details
Create a Python program that defines the function
is_point_in_rectangle(point_x, point_y,
rectangle_center_x, rectangle_center_y, rectangle_width,
rectangle_height)
. The function has 6
parameters. The first two parameters, point_x
and point_y are the x and y coordinates of a point.
The next two parameters rectangle_center_x
and rectangle_center_y) the x and y coordinates of the
center of a rectangle. The last two
parameters rectangle_width
and rectangle_height the width and height of the
rectangle.
The function should return True if the point is inside the rectangle. Assume a point exacty on the border of the rectangle is inside the rectangle. The function should return False if the point is not inside the rectangle.
Test Cases
print('Input: ?, ?, ?, ?, ?, ?\t\tActual:', is_point_in_rectangle(?, ?, ?, ?, ?, ?), '\tExpected:', ?)
- To test if a point is in a rectangle, you must compare the point's location to the location of each of the sides of the rectangle.
- You are given the center point of a rectangle, but to check if a point is inside of a given rectangle you need to be able to compute the x coordinate for the left and right sides of the rectangle and the y coordinate of the top and bottom of the rectangle. Create variables for these, so your logical expressions will be more readable.
Challenge
Modify the program to be visual like the Point in Circle program from last class. The program should draw a rectangle in the center of the screen that takes up about half of the window. And it should randomly generate points that are colored green or red depending on whether they are inside of the rectangle.