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 18:50
What is transmission control protocol/internet protocol (tcp/ip)? software that prevents direct communication between a sending and receiving computer and is used to monitor packets for security reasons a standard that specifies the format of data as well as the rules to be followed during transmission a simple network protocol that allows the transfer of files between two computers on the internet a standard internet protocol that provides the technical foundation for the public internet as well as for large numbers of private networks
Answers: 2
question
Computers and Technology, 23.06.2019 21:40
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings. for each match, add one point to user_score. upon a mismatch, end the game. sample output with inputs: 'rrgbryybgy' 'rrgbbrybgy'
Answers: 3
question
Computers and Technology, 23.06.2019 22:30
Lakendra finished working on her monthly report. in looking it over, she saw that it had large blocks of white space. what steps could lakendra take to reduce the amount of white space?
Answers: 3
question
Computers and Technology, 24.06.2019 21:30
How is a wan different than a lan? both connect computers, but only wan users don’t need the same operating system. both are peer-to-peer networks, but only a wan requires networking hardware. both network computers, but only a wan can cover larger geographical ranges. both connect computers to the internet, but only wan connects to the cloud.
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, 13.02.2021 01:10
question
Mathematics, 13.02.2021 01:10
Questions on the website: 13722360