Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

Objectives

The objectives of this assignment are:
- To gain experience in designing algorithms for a given problem description and implementing those algo- rithms in Python 3.
- To demonstrate the ability to:
- Implement algorithms for sorting in Python.
- Decompose code into functions in Python.
- Implement simple recursive algorithms in Python.
- Read from text files using Python.
- Manipulate lists using basic operations.

Task 1:

Part A

(a) File read in correctly

(b) Merge sort implemented correctly (c)Rankings printed correctly

(d)Code is readable (including meaningful variable names and non-trivial comments on code)

(e)Code is appropriately decomposed

Part B

(a) File read in correctly

(b) Merge sort implemented correctly

(c)Rankings printed correctly

(d) Code is readable (including meaningful variable names and non-trivial comments on code) - 1 marks (e)Code is appropriately decomposed

Task 2:

(a) File read in correctly - 2 marks (b)Maximum spanning tree found - 3 marks (c)Spanning tree printed correctly

(d) Code is readable (including meaningful variable names and non-trivial comments on code)

(e)Code is appropriately decomposed

Task 3:

Part A

(a) Recursive function(s) implemented correctly - 3 marks (b)Mathematical function(s) implemented correctly

(c) Code is readable (including meaningful variable names and non-trivial comments on code)

(d)Code is appropriately decomposed

Part B

(a) Report conclusions and quality

Task 1

For this year's Olympic games, as always, the ranking of the teams is given by the number of medals that they win in the various events. The number of medals that each team won is stored in a file with one team per line. Each line contains a team's name, followed by the number of gold, silver and bronze medals they won. The values on each line are separated by commas. An example of the format is shown below.

Canada (CAN),1,5,12
Indonesia (INA),0,1,1 Poland (POL),2,2,6

Part A

For this part, you are to write a Python program to sort the teams by the number of gold medals that they won. Perform this sort using Merge sort. The program should ask the user for a filename containing the medal tally and read the file in. It should then sort the teams by their number of gold medals and finally print the teams in their sorted order along with their rank. Note that multiple teams can have the same rank if they have the same number of medals. For example, given a file containing the above tally, the program could print:
Sorted according to the number of gold medals

1: Poland (POL)
2: Canada (CAN)
3: Indonesia (INA)

Part B

In this part, write a Python program similar to the one from Part A but sort by the total medal count instead. So instead of sorting by the number of gold medals that each team won, this time it should be sorted by the total number of medals (gold, silver and bronze) that the team won.

For this part, your program might print the following:

Sorted according to the total number of the medals 1: Canada (CAN)
1: Poland (POL)
2: Indonesia (INA)

Task 2

Previously in this unit, we have discussed finding minimum spanning trees using a variety of methods. In this task, we will be finding maximum spanning trees, that is spanning trees with the highest possible weight.

Create a Python program which finds a maximum spanning tree of a given graph. Your program will ask the user for a filename and read a graph, stored as an edge list, from that file. It will then compute a maximal spanning tree from that graph and print the edges in the tree along with its weight. For example: The file containing the following lines:

0

1

1

0

4

8

0

5

9

1

2

17

1

4

6

2

3

2

3

4

9

4

5

3

2

4

12

For example: If the file testGraph.txt contains the edges and weights of the graph (see figure 1), your program might do the following:

2129_Figure1.jpg

This is the edges of the spanning tree

[[0,5],[0,4],[4,2],[2,1],[4,3]]

The weight of the maximum spanning tree is: 55

Task 3

A combination is a way of selecting k elements from a set of n elements. The total number of ways of doing this for a given n ≥ 0 and k ∈ [0, n] is denoted (nk). The value of (nk) can be calculated using (1) below where n! is the factorial of n.

(nk) = n!/((n - k)!k!)

The following identity involving a sum of a number of combinations allows for it to be calculated more simply:

Σnk=0(nk)xk/k=1 = ((x +1)n+1 -1)/x(n +1)

Part A

For this task, you are to attempt to verify the correctness of this identity. Do this by implementing both the left-hand and right-hand sides of the equation as functions in Python.

Using these two functions, create a program which takes values for x and n and prints the result of both the left-hand and right-hand sides of the identity for those values.

Your program should include at least one non-trivial recursive function. You must not use the math package and must write your own function to compute (nk).

Part B

Using your program from Part A, compare the results for both functions for a variety of values of both x and n. Choose at least 10 combinations of values and present your results in a table. Include this table in a short report (about 2 paragraphs) and discuss whether your results indicate that the identity is true.

Python, Programming

  • Category:- Python
  • Reference No.:- M92072405
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in Python

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

A software company sells a package that retails for 99

A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program using python t ...

Question write a python program with a graphical user

Question: Write a python program with a graphical user interface that will allow a user to create a custom pizza which they wish to order. At minimum, the user should be able to choose the size of the pizza, the type of ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

Python programming assignment -you first need an abstract

Python Programming Assignment - You first need an abstract base class, called, Account which has the following attributes and methods: accountID: This attribute holds the ID assigned the account , if not provided set to ...

Sieve of eratosthenes in pythonthe goal is to find all the

Sieve of Eratosthenes (in Python) The goal is to find all the prime numbers less than or equal to some natural number maxn. We have a list that tells us if any of the numbers 0..maxn are "marked". It can be an array of b ...

Below zero - ice cream storethe local ice-cream store needs

Below Zero - ice cream store The local ice-cream store needs a new ordering system to improve customer service by streamlining the ordering process. The manager of the store has found that many orders are incorrect and s ...

In this programming assignment you will write a client

In this programming assignment, you will write a client pingprogram in Python. Your client will send a simple ping message to a server, receive a correspondingpong message back from the server, and determine the delay be ...

Simple python traffic lightswrite a program that simulates

Simple Python (Traffic lights) Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and onl ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As