Third Practicum: Wednesday, May 10

Practice Practicum Problems

Question 1

Conduct experiments with the Python code below until you can describe in simple English what is true of the variable answer after the while loop finishes.

answer = ""
while (not answer.isnumeric()):
    answer = input("Enter something: ")

Hint: Use the Python documentation to learn more about the isnumeric() method.

Question 2

Modify the recursive function below so that same size, smaller squares are drawn in both the upper left hand and lower right hand corners of larger squares.

import turtle

def square(square_turtle, upper_x, upper_y, width):
    square_turtle.up()
    square_turtle.goto(upper_x, upper_y)
    square_turtle.down()
    for side in range(4):
         square_turtle.forward(width)
         square_turtle.right(90)

def recursive_squares(my_turtle, x, y, width, level):
    if (level > 0):
         square(my_turtle, x, y, width)
         recursive_squares(my_turtle, x, y, width/3, level-1)

squares = turtle.Turtle()
squares.color("blue")
recursive_squares(squares, -200, 200, 400, 3)
squares.hideturtle()

Question 3

Write a function named eliminate_consonants that strips out all consonants from the word that it is given. For example, if eliminate_consonants is called with "mississippi", it should return "iiii".

result = eliminate_consonants("mississippi")
print(result)     # should print "iiii"

Question 4

A year is a leap year if it is divisible by 4 unless it is a century that is not divisible by 400. Write a function that takes a year as a parameter and returns True if the year is a leap year, False otherwise.