CISC121 Introduction to Computing Science I Assignment2 Python代写

https://www.cs.queensu.ca/undergraduate/courses/CISC-121

import random

def tortoise_move():

    ”’Random tortoise movement:

        – Fast plod, 50%, +3

        – Slip, 20%, -6

        – Slow plod, 30%, +1

    Parameters:

        None

    Returns:

        move (int): the random move of tortoise this time.

    ”’

    moves = [3, -6, 1]

    move = random.choices(moves, weights=(50, 20, 30), k=1)[0]

    return move

def hare_move():

    ”’Random hare movement:

        – Sleep, 20%, 0

        – Big hop, 20%, +9

        – Big slip, 10%, -12

        – Small hop, 30%, +1

        – Small slip, 20%, -2

    Parameters:

        None

    Returns:

        move (int): the random move of hare this time.

    ”’

    moves = [0, 9, -12, 1, -2]

    move = random.choices(moves, weights=(20, 20, 10, 30, 20), k=1)[0]

    return move

def main():

    ”’Main logic of the game”’

    # both tortoise and hare start at position 1

    tortoise = 1

    hare = 1

    print(‘BANG!!!’)

    print(‘AND THEY ARE OFF!!!’)

    # loop until tortoise or hare arrives position 70

    while tortoise < 70 and hare < 70: