Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python (retired) Inheritance __str__

Nursultan Bolatbayev
Nursultan Bolatbayev
16,774 Points

Random choice

Hello. When I create new instances of Monster class or subclass of Monster with max and min attributes, why it always gives the max value (for hit_points and experience)? But it should be a random between max and min which is defined in def init()?

Can you please share your code by pasting it here inside code blocks (refer to the Markdown Cheatsheet linked below the question/answer/comment box), or by creating a Snapshot of your Workspace if you're using Workspaces?

1 Answer

Matthew Hill
Matthew Hill
7,799 Points

Without seeing your code it's difficult to give a proper answer, however, in your title for this question you said 'choice'. You should be getting a random integer from within the two specified parameters:

<p>
import random
minimum = 1
maximum = 5
example = random.randint(minimum, maximum)
</p>