联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-11-22 10:18

Coursework 2

4CCS1PRP Programming Practice

Outline

This piece of coursework will make up to 15% of your final grade for this module.

The tasks focus on topic 9, but also covers the first 8 topics of material.

You will need to download the coursework2.py file from KEATS.

Submission and deadline

You must submit your solutions electronically, via a submission link on KEATS.

Your solutions should be contained within a single Python program. You should submit only

your edited coursework2.py extension.

You must submit by Saturday 1st December, 23:55. Late submissions will receive a mark of

0, even if they are only a minute late. Make sure you submit before the deadline.

Marking criteria

Your submission will be marked for the following criteria.

– Completeness: How many tasks have been completed?

– Correctness: Do the solutions work as specified?

– Commenting: Is there a sensible level of useful comments?

– Style: Is the code readable and well-formatted?

Support

If you have questions about the coursework, use the discussion forum on the KEATS page.

However, do not post any of your code on the forum, this is collusion.

You are expected to work on the coursework in your own time’ not in lectures, labs, or SGTs.

1

Tasks

You will need to download the coursework2.py file.

This file contains the import statements necessary for the corusework, and a function new_deck().

You should not edit the new_deck() function contained in the file.

Isntead, you should add all your code underneath the function.

If it would improve the structure of your code, you may declare functions in addition to

those that are explicitly required.

Task 1

Familiarise yourself with the provided function, new_deck().

For simplicity, a tuple (F, H) will be referred to as a card.

Declare a variable my_deck, and initialise it with a standard 52-card deck.

Task 2

Write a function, two_random_elements() that takes a list of elements as input, and returns

two random elements of the list as a tuple (e2, e2).

Each element of the list should have an equal probability to be returned.

The two elements returned should be distinct.

– e.g. your function should never return the same element twice.

The function should not have any side effects.

Ensure the function returns a suitable value int he case there are fewer than two elements

in the input list.

Call your function with my_deck to print out three random pairs of cards from the deck.

Task 3

Write a function card_pair_value() that takes two cards as input and returns their pair

value.

The value of a pair of cards is the product of their individual values.

A card’s individual value is determined as follows.

– If the card has a numeric face, 2–10, the value of the card is its number.

– If the face is a jack, queen, king, or ace, the value of the card is 10.

– The suit has no effect on the card’s value.

Call your function with three random card pairs from my_deck and print their values. Your

random card pairs should be obtained by calling the function two_random_elements().

2

Task 4

Write a function, pair_value_hist() that takes a list of cards as input.

The function must plot a histogram of the frequency of the pair values obtained by taking

10,000 random pairs of cards from my_deck.

Your histogram should have a custom bin size of 1, for bins from the minimum possible value

of a pair of cards (4), to the maximum possible value (100).

Task 5

Declare a matrix, A, such that:

A =

1 4 5

2 8 9

3 6 7

Print out AT

, the transpose of A.

Print out A?1

, the inverse of A.

Print out A?1 × AT

, the multiplication of the transpose of A and the inverse of A.

Task 6

Plot a line graph of the following function, over the domain [0, 4π) in intervals of 10?2

.

y = √

1

e

0.5x

2

Note that e, the base of the natural logarithm, is included as a mathematical constant in

the numpy library in the same way the π is.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp