Exercise 1 Prices for terrace tables You must build on the program which is located in planke_priser.py and which is distributed below. Based on this program, write a program that calculates the price...

1 answer below »
exam python


Exercise 1 Prices for terrace tables You must build on the program which is located in planke_priser.py and which is distributed below. Based on this program, write a program that calculates the price of a series of patio tables. The price is stated per. meters in the constant PRICE_PR_METER in the code. Your code should ask the user the length of the terrace tables and the number of terrace tables. Your program should ask for more such lengths and exit when the user enters 0 or lower as length. An example run where the customer must have 6 planks of 5 meters each, 8 planks of 3 meters each, and 4 planks of 2 meters each are given here: Calculate price for terrace table: Length. End with 0 or negative number: 5 Number: 6 Preliminary sum: 412.50 Length. End with 0 or negative number: 3 Number: 8 Preliminary sum: NOK 742.50 Length. End with 0 or negative number: 2 Number: 4 Preliminary sum: NOK 852.50 Length. End with 0 or negative number: 0 Total amount: 852.50 kr You must enter your code where the comment "Write your code here!" stands. You should use the features read_in_in integer and read_in_move number from the specified code to read in numeric values. exercise 2 A program that rolls five dice and describes where this can be placed in a yatzy game is given below, and in file reduced_yatzy.py The program should do the following: - Have a loop that ends when the user requests it. For each iteration: - Roll 5 dice - Check how many points this roll of the dice would have given if it had been placed in the following boxes. Wanted given 0 points, the program should not print that box: - 1s, 2s etc: In the 1s box you score equal to the sum of all dice showing the number 1. In the 2s box for you score equal to the sum of all dice showing the number 2, and so on. - One pair: The sum of the numbers on the two dice that gives the highest pair if there are at least two dice that shows the same value. - Three of a kind: If there are three or more dice that show the same value, print the sum of the points from three of them. - Four equals: If there are four or more dice that show the same value, print the sum of the points from four of them. - Straight: If the dice can be sorted so that they are in a row, ie 1, 2, 3, 4, 5 or 2, 3, 4, 5, 6, print the sum of all the dice. Otherwise 0. The program has the following issues that you need to fix. Each problem is worth 3%: 1. It never gives out points for 6s no matter how many dice show the number 6. 2. If there are two pairs, for example 1, 3, 2, 1, 3 that contain a pair of 1s and a pair of 3s, then it should print the highest, 6 points in the example. Instead, it prints the lowest, 2 points in the example. 3. If you get a straight, you get an exception "IndexError: list index out of range" in line 38. 4. When the program is to check for yatzy you get an exception "TypeError: object of type 'int' has no len ()" in line 47. Write your answer here Exercise 3 Boiled loops Write a function that can print the figures given below. The function should take a parameter, which gives the size of the figure exercise 4 Polymorphism: Geometry tests Given the classes Rectangle and Figure Viewer below, which are also in the file er_inni_program.py in the distributed code. Exercise a Write a class Circle that should work in the Figure Viewer class. the class Circle must be able to be an element in the list "self.object list" in the class Figure viewer and should have all the properties needed to work here. The only thing you will need to modify in the class Figure viewer is possibly the __init__ method for entering someone sample circles in the list. Otherwise, neither Rectangle nor Figure Viewer should be modified. A circle is defined by a center with x and y coordinates as well as a radius. Here is a list of properties to circles. You do not have to implement all for this task - finding out which ones are necessary is part of the task: .Area: pi * radius * radius .Diameter * 2 * radius .Circumference: 2 * pi * radius .Point is inside circle: the distance from the point to the center of the circle is less than or equal to the radius of the circle .Two circles overlap: Distance between the centers is lower than the sum of the radius of the two circles Distance between two points is where x and y are the distance between the two points in the x- and y- direction. Exercise b Write a class Box that will work in the Figure Shaper class in the same way as Rectangle and Circle. The the only thing you will need to modify in the Figure Viewer class is possibly the __init__ method of entering someone sample boxes in the list. Otherwise, neither Rectangle, Circle, nor Figure Viewer should be modified. A box consists of two rectangles, one inside the other. A point is inside the box if it is inside the outside rectangle but outside the interior. The area is the area of the outer rectangle minus the area of the inner. Note that is part of the task that your code ensures that the inner rectangle is actually inside the outer rectangle. It easiest method to do it is to make sure that the start coordinate and the corner diagonally opposite for it are inside. Write your answer here Exercise 4 GUI: Regional draftsman Distributed code: .The file geometry_example.py is a merger of the point example and the extended geometry example and contains the classes Dot, SegmentLine and Region .The file linjetegner.py contains GUI for drawing a line with many line segments. Based on these two, you will change line drawing.py to draw regions instead. In addition to the functionality of it distributed line designer, your program should include the following features: 1. You should create a "exit region" button. This button is used to indicate that you are now done draw one region, and must begin on the next. This button should do two things 1. Draw the region as a polygon in the Canvas 2. Create an object of the assigned class Region, and insert this into a list of regions. 2. When the program exits, it should print all the regions. Use standard printing for the regions. You can draw a polygon in tkinter based on a list of coordinates with the method create_polygon (list_of_coordinates, fill = color) This picture shows what the region designer can look like after drawing three regions but has not yet started on it fourth.
Answered 135 days AfterMay 14, 2021

Answer To: Exercise 1 Prices for terrace tables You must build on the program which is located in...

Aditya answered on May 19 2021
145 Votes
Answer Submitted
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here