subject

1. Create a function that receives a single positive integer, and returns a list of three random integers between 1 and [the received integer] inclusive. 2. Consider the following: A triangle has three sides of non-zero length, where no one side-length can be equal to or greater than the other two sides combined. For example, it is impossible to have a triangle with side-lengths 2, 2, and 5 (see Figure 1). Create a function in your library, that receives a list of three positive integers, and outputs True or False depending on whether it is possible to make a triangle with those length of sides.

3. A triangle can be described as right-angled if the sum of the squares of two of its sides, is equal to the square of the remaining side. You should recognise the equation a2 + b2 = c2, where a, b and c, are the three side lengths. Create a function that receives a list of three positive integers, and returns True or False depending on whether it is possible to make a right-angled triangle using those length of sides. Figure 2 shows an example triangle. It is important to remember, that this example could be represented with multiple different lists, e. g: [3,4,5], [4,5,3], [5,3,4]… so you can not assume that the received list has a, b, and c in that order.

Figure 1: Showing an impossible triangle

Figure 2: Showing a right-angled triangle stored as [5,3,4]

4. Create a Python class for dice (the type that you roll while playing a game). Remember that the singular is ‘die’ and the plural is ‘dice’. Dice should have:
• Two attributes: the amount of sides they have (4,6,8,10,12 or 20), and the side that is currently face up (which should be initialised to a random side).
• A method to ‘roll’ the die, effectively selecting a random side to become ‘face-up’.
• A __str__ method that is appropriate.

5. Create a class for a dice bag, which will hold one of each type of die. Its __str__ method should appropriately show all the dice in the bag, as well as their current ‘face-up’ sides. It should have a method that rolls every dice in the bag; and a method to add a die to the bag.

6. In your dice bag class, write a method that receives a single input string in the format ‘#d#’, where the first number (#) represents the number of dice, and the second number represents the number of sides that those dice have. For example, 2d4 would mean 2 dice, each with 4 sides.

The method should:
• Create the requested amount of dice with that many sides.
• Roll the dice using the correct method.
• Display (print) the results of that dice roll in order, to a single line in the console.
For example, if you passed the method ‘4d6’ it would create four 6-sided dice (using your previously made class), roll them, sort them by result, and display the results in the console in order. In this example, if the dice that were rolled were 2, 3, 6, and 1; it should print them as ‘1, 2, 3, 6’. Note that the created dice are never added to the dice bag.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 13:00
In excel - calculate the actual increase/decrease from first quarter to the second quarter then subtract subtract first quarter value from second quarter total then divide result by first quarter value
Answers: 1
question
Computers and Technology, 24.06.2019 09:40
Healthy study habits are best described as
Answers: 1
question
Computers and Technology, 24.06.2019 12:00
What is a sketch or blueprint of a web page that shows the structure (but not the detailed design) of basic page elements such as the logo, navigation, content, and footer?
Answers: 3
question
Computers and Technology, 24.06.2019 13:00
Ais a built in formula in spread spread a is any math process such as addition or subtraction. options are function and operation
Answers: 1
You know the right answer?
1. Create a function that receives a single positive integer, and returns a list of three random int...
Questions
question
Mathematics, 29.03.2021 03:40
question
English, 29.03.2021 03:40
question
English, 29.03.2021 03:40
question
Mathematics, 29.03.2021 03:40
question
Mathematics, 29.03.2021 03:40
question
Mathematics, 29.03.2021 03:40
Questions on the website: 13722367