[SOLVED] python Skip navigation

$25

File Name: python_Skip_navigation.zip
File Size: 207.24 KB

5/5 - (1 vote)

Skip navigation

PROGRAMMING FOR SCIENTISTS S2 2019
ANU College of Engineering & Computer Science

COMP1730/6730
Course content & schedule
Labs
Assessment
Archive

1.Home COMP1730/6730: Assessment Homework 2 (S2 2019)
Homework 2 (S2 2019)
Homework 2 (S2 2019)
This is the second homework assignment. Your goal in this assignment is to write a function that performs a calculation and returns a value.
Practical information
The assignment is due on Monday the 12th of August, at 11.55pm. To submit your solution, upload a single python file via wattle. Here is the assignment submission link.
In addition to submitting your solution, you must attend the following lab (in week 4). In the lab, your tutor will ask you some questions about your solution, and give you feedback if there is anything you need to improve. This discussion with the tutor is also part of the assessment.
If you fail to show up for the discussion with the tutor, you will receive zero marks for this assignment. If you do not submit a solution, you may still get partial marks for the discussion with the tutor.
The homework is individual. You must write your own solution, and you are expected to be able to explain every aspect of it.
If you have followed the lectures and worked through the exercises in lab 2, the assignment should not take more than one or two hours to complete.
The problem
Calculating the number of ways to select k distinct elements from a set of n is one of the most famous problems in combinatorics. This number is often called n choose k, or the binomial coefficients. We will call it combinations(n, k), because you will implement it in a function called combinations.
There are several ways to compute this number, but the one that most students find easiest is the formula
n!
k!(nk)!

n
!
k
!
(
n

k
)
!
where
n!
n
!
is the factorial function of
n
n
. The factorial of 0 is defined to be 1, so that the combinations formula works also when n or k are zero.
Your task is to write a function combinations(n, k) that computes and returns the n choose k, or combinations(n, k), number.
The function must take two arguments (that is, have two parameters), and it must return an integer value (a value of type int).
We provide you with a skeleton code file: combinations.py. Download this file and write in it your implementation of the function.
The skeleton file already has in it several functions: one is an implementation of the factorial function, which you can use in your combinations function; the other are testing functions that you can (and should!) use to test if your function is working correctly.
Testing
The skeleton file has two testing functions:
test_combinations() This function runs a number of tests of your function, and produces an error message if any of the tests fail. If all tests are ok, it will print the message all tests passed.
print_pascals_triangle(n) This function prints the first n rows of Pascals triangle, which is made up of combinations numbers. n must be a positive integer. For example, print_pascals_triangle(5) should print1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
This function will only print the numbers in Pascals triangle (as computed by your combinations function), it will not check that they are correct. You have to do that by comparing it with the expected output.
Marking
What to submit
You should edit the skeleton file combinations.py that you downloaded, then upload only this file with your solution using the assignment submission link on wattle.
The file that you submit must meet the following requirements:
It must be syntatically correct python code.
Like the file you downloaded, it must contain only function definitions; comments, including docstrings (if they are used appropriately) are of course ok to include. Anything that is not a function definition will be ignored when we check your submission.
You should not modify the testing functions.
As mentioned above, you must also attend the following lab (in week 4) and answer your tutors questions about your solution. This discussion is part of the assessment. You should be prepared to answer or demonstrate to the following questions:
Can you download the file that you submitted from wattle?
Can you run that file in the python interpreter (using an IDE of your choice) on the CSIT lab computer?
If the file has syntax errors, can you use the error messages from the interpreter or IDE to identify where the syntax errors are?
Does your submitted file meet the requirements stated above? Does it contain anything that is not a function definition? If so, can you point it out?
Does your function pass all the tests run by the unmodified test_combinations() function?
Does your function correctly compute and return the number of combinations for any valid arguments (non-negative integers n and k, with 0 <= k <= n).Does your function always return a value of the correct type?Can you think of any other test cases that should be used to test your function, in addition to or instead of those in test_combinations()?How did you choose to calculate the number? Which formula or method did you use, and why?What is the difference between the print function and the return statement?In marking this assignment we will consider the following:Does your submitted file satisfy the requirements specified above?Does your implementation of the combinations function compute the correct value for all argument values?Your ability to use the tools (e.g., the IDE or python interpreter), your understanding of pythons error messages, and your understanding of the solution, as demonstrated in your discussion with the tutor.The assignment is worth 2% of your final mark.Updated:05 Aug 2019Responsible Officer:Head of SchoolPage Contact:Patrik HaslumContact ANUCopyrightDisclaimerPrivacyFreedom of Information+61 2 6125 5111The Australian National University, CanberraCRICOS Provider : 00120CABN : 52 234 063 906

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] python Skip navigation
$25