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 17:00
The more powerful, 60 volt cables and the main power shut-off on an hev are both colored orange.
Answers: 1
question
Computers and Technology, 24.06.2019 07:30
Consider the folloeing website url: what does the "http: //" represent? a. protocal identifier. b. ftp. c. domain name d. resource name
Answers: 2
question
Computers and Technology, 24.06.2019 13:30
What process should be followed while giving a reference? sam has given a reference of his previous manager in his resume. sam should him in advance that the potential employers will him.
Answers: 1
question
Computers and Technology, 24.06.2019 17:00
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
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, 27.08.2019 09:30
Questions on the website: 13722363