Computers and Technology

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.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:40, vanessacasillas452
In the lab, which of the following displayed a list of all installed services and included a description of the service, the current state, and whether the service started automatically or manually? a. the services manager b. the applications summary c. the recommended services d. list the safe services list
Answers: 2
image
Computers and Technology, 22.06.2019 10:00, danthehero56
Which of the following is true of operations within a spreadsheet program’s built-in functions? a. operations within parentheses, then multiplication and division, and then addition and subtraction are computed. b. operations within parentheses, then addition and subtraction, and then multiplication and division are computed. c. multiplication and division, then addition and subtraction, and then operations within parentheses are computed. d. addition and subtraction, then multiplication and division, and then operations within parentheses are computed
Answers: 2
image
Computers and Technology, 22.06.2019 14:20, babyrocks7300
Consider a byte-addressable computer with 16mb of main memory, a cache capable of storing a total of 64kb of data and block size of 32 bytes. (a) how many bits in the memory address? (b) how many blocks are in the cache? (c) specify the format of the memory address, including names and sizes, when the cache is: 1. direct-mapped 2. 4-way set associative 3. fully associative
Answers: 2
image
Computers and Technology, 22.06.2019 21:00, mazolethrin9632
Which of these is most responsible for differences between the twentieth century to the twenty-first century?
Answers: 2
Do you know the correct answer?
1. Create a function that receives a single positive integer, and returns a list of three random int...

Questions in other subjects:

Konu
Mathematics, 13.07.2019 15:50