Primes Problem

Write a function, is_prime, that takes a single integer argument and returns True when the argument is a prime number and False otherwise.

# primes.py

def is_prime(prime):
    for number in range(2, prime):
        if prime % number == 0:
            return False

    return True

print(is_prime(17))
print(is_prime(20))

Modifying Randomly Walking Turtles

Modify the turtle walk program so that you have two turtles each with a random starting location. Keep the turtles moving until one of them leaves the screen.

Pick a Number

Write a program to simulate the simple “Pick a number between 1 and 10” game. The program should continue running until user guesses the correct number.

# guess.py

import random

# ask user for number
print("I'm thinking of a number between 1 and 10...")

secret = random.randint(1, 10)  # pick the secret number
guess = 0                       # initialize guess to 0

while guess != secret:
    guess = int(input("Guess the number: "))
    
    # check if user's answer is the number
    if guess == secret:
        print("You guessed it!")
    else:
        print("WRONG! Try again...")