Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE PYTHON 3.10 and make sure the code works , STARTER CODE AND SAMPLE TESTS GIVEN: Prep 2 STARTER CODE === Module Description === This

USE PYTHON 3.10 and make sure the code works ,

STARTER CODE AND SAMPLE TESTS GIVEN:

"""Prep 2 STARTER CODE === Module Description === This module contains the documentation for a simple class. Your job is to implement the class below according to its docstring; note this includes both the *instance attributes* of the class and the *methods* we've documented. As usual, delete the TODO comments after you've completed each part. """ # Do not use any imports beyond the one below (randint)! from random import randint class Spinner: """A spinner for a board game. A spinner has a certain number of slots, numbered starting at 0 and increasing by 1 each slot. For example, if the spinner has 6 slots, they are numbered 0 through 5, inclusive. A spinner also has an arrow that points to one of these slots. === Attributes === slots: The number of slots in this spinner. position: The slot number that the spinner's arrow is currently pointing to. === Sample Usage === Creating a spinner: >>> s = Spinner(8) >>> s.position 0 Spinning the spinner: >>> s.spin(4) >>> s.position 4 >>> s.spin(2) >>> s.position 6 >>> s.spin(2) >>> s.position 0 """ slots: int position: int def __init__(self, size: int) -> None: """Initialize a new spinner with  slots. A spinner's position always starts at 0. Precondition: size >= 1 """ # TODO: complete this method! pass def spin(self, force: int) -> None: """Spin this spinner, advancing the arrow  slots. The spinner wraps around once it reaches its maximum slot, starting back at 0. See the class docstring for an example of this. Precondition: force >= 0. Hint: use the "%" operator to "wrap around" the spinner's position. """ # TODO: complete this method! pass def spin_randomly(self) -> None: """Spin this spinner randomly. This modifies the spinner's arrow to point to a random slot on the spinner. Each slot has an equal chance of being pointed to. You MUST use randint (imported from random) for this method, to choose a random slot. """ # TODO: complete this method! pass if __name__ == '__main__': # When you run the module, you'll both run doctest and python_ta # to check your work. import doctest doctest.testmod() # python_ta opens up your web browser to display its report. # You want to see "None!" under both "Code Errors" and # "Style and Convention Errors" for full marks. import python_ta python_ta.check_all(config={ 'extra-imports': ['random'] })

SAMPLE TESTS :

from hypothesis import given from hypothesis.strategies import integers from prep2 import Spinner # This is a hypothesis test; it generates a random integer to use as input, # so that we don't need to hard-code a specific number of slots in the test. @given(slots=integers(min_value=1)) def test_new_spinner_position(slots: int) -> None: """Test that the position of a new spinner is always 0.""" spinner = Spinner(slots) assert spinner.position == 0 def test_doctest() -> None: """Test the given doctest in the Spinner class docstring.""" spinner = Spinner(8) spinner.spin(4) assert spinner.position == 4 spinner.spin(2) assert spinner.position == 6 spinner.spin(2) assert spinner.position == 0 if __name__ == '__main__': import pytest pytest.main(['prep2_sample_test.py'])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals of Financial Management

Authors: Eugene F. Brigham, Joel F. Houston

15th edition

1337671002, 978-1337395250

More Books

Students also viewed these Programming questions

Question

Does the person have her/his vita posted?

Answered: 1 week ago

Question

9.3 Evaluate methods used to treat eating disorders.

Answered: 1 week ago