Ask Python Expert

The goal of this exercise is to write a \business phrase" generator, which each time it is called produces lines of business speak, such as:

It's time that we became uber-efficient with our interactive policy hardware At base level, this just comes down to holistic relative consulting Only geeks stuck in the 90s still go for functional modular capability We need to get on-message about our 'Outside the box' modular matrix approaches The idea is very similar to the \Eureka Machine" discussed in lectures: to produce a business speak phrase, your program should randomly select and print a phrase from each of four lists in turn.

These lists are stored in files named beginning.txt, adjective.txt, inflate.txt and noun.txt, which can be downloaded from the resources website;1 a business speak phrase is constructed by selecting a phrase from each of these in the order beginning.txt, adjective.txt, inflate.txt and noun.txt.

Write a program that will read the required words and phrases from the _les and print _ve business speak phrases. The program should be organised so that it can easily be changed to print any number of phrases.

You should submit:

1. A brief explanation of how your program is structured and why you have structured it that way.

2. An example of the output of your program, cut-and-pasted from the command prompt or a screenshot.

3. A hardcopy of the program.

4. Your program in a file business.py.

Hints:

1. You may use the dice.choose function discussed in lectures.

2. As before, you can read all the lines in a file with lines = open ('myfile .txt ', 'r'). readlines () myfile.txt must be in the same directory as your program. Remember that each line will have a newline character at the end.

3. You can remove the newline and any other whitespace from a string using strip: for example:

>>> s = ' string with spaces at the beginning and end \n'

>>> s ' string with spaces at the beginning and end \n'

>>> stripped = s. strip ()

>>> stripped 'string with spaces at the beginning and end '

Shuffling. One way to shuffle a deck of cards or a list is to repeatedly choose a pair of cards/items at random and to swap their positions in the deck/list. Write a function shuffle(L, nswaps) which shuffles the list L in-place using this method, swapping pairs nswaps times. Write a test function that uses assert statements to check that none of the elements of a list of integers are lost and none are gained by the shuffling.

How many swaps are needed to properly shuffle the list? Clearly one or two swaps don't make much difference, but for a small list there's not much point in doing thousands of swaps. To answer this question we can define the quality of a shuffle as the fraction of times the second element of two adjacent elements is larger than the first. Thus the sorted list [0, 1, 2, 3, 4, 5, 6] has a quality 6=6 = 1 because every element is greater than the previous one, whereas the list [1, 4, 2, 3, 6, 5, 0] has a quality 3=6 = 0:5 because the pairs (1; 4); (2; 3); (3; 6) have the second element greater than the first, but the other pairs (4; 2); (6; 5); (5; 0) do not. A well-shuffled list will have a quality close to 0.5.

Write a function quality(L) that evaluates how well the list L is shuffled. Then write a function average quality(nswaps)that uses these functions to evaluate the average quality of a shuffle of the list of integers range(50), using nswaps swaps. To get reliable answers you will need to take the average over, say, 30 different shuffles. Finally, write a program that prints out the average quality of a shuffle of a list of length 50 using 5, 10, 15, . . . , 200 swaps.

The code should be in a file named shuffle.py. Organise the code so that the functions can be imported into other programs and the average qualities are printed out when the module is run as python shuffle.py. How many swaps do you think is a good number for a list of length 50? How many for a list of length N?

You should submit:

_ A paper copy of the code. (Via BART.)

_ A paper copy of the output of a run of your program, showing the qualities for different

numbers of swaps. (Via BART.)

_ A hard copy of your code. (Via BART.)

_ An electronic copy of your program in a _le named shuffle.py. (Electronic submission.)

The stylised picture of a fern (above) is an example of a fractal, an object with non-integer dimension, similar to the Koch curve from workshops. The dimension of this one is di_cult to calculate, but is something between a line, with dimension 1, and a plane, with dimension 2. Fractals are extensively used in describing and modelling natural objects with structure on many length scales, such as the coastline of Great Britain, the shape of clouds, the distribution of stars in the universe, the structure of intestinal walls, plants and so on. They are also used in computer graphics to make realistic models of terrain and natural scenery. The classic reference for fractals is Mandelbrot's book, The Fractal Geometry of Nature, which is in the library; there is lots of recent information on the web.

The details of the recursive construction are illustrated below.

The left hand picture shows the basic shape; in the full fern each of the branches is recursively replaced by a scaled down copy of the shape. The right hand picture shows the next level of the construction.

As shown in the pictures, the two top branches are each half as long as the original main trunk, while the branch on the left is situated halfway along the main trunk. The angles which the branches make with the trunk are not crucial, but suggested values are shown on the diagram. Thus to draw a fern with a turtle, the turtle should start at the base of the trunk and do the following:

(a) Draw the trunk;

(b) Turn left by 30_ and draw a fern at half the scale;

(c) Turn right by (30 + 40)_ and draw a fern at half scale;

(d) Move back to halfway along the trunk; turn left by 80_ and draw a fern at 0.3 scale;

(e) Move back to the base of the trunk.

Python, Programming

  • Category:- Python
  • Reference No.:- M9528644

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

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 ...

Tasksdemonstrate data scraping of a social network of

Tasks Demonstrate data scraping of a social network of choice. Develop technical documentation, including the development of the code & detailing the results. Provide a report on the findings, that includes research into ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

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 ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Question research pythons dictionary data type dictdiscuss

Question : Research Python's dictionary data type (dict). Discuss its interface and usage. Include examples. Discuss practical applications of dictionaries.

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.

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 ...

The second task in this assignment is to create a python

The second task in this assignment is to create a Python program called pancakes.py that will determine the final order of a stack of pancakes after a series of flips.(PYTHON 3) Problem Task In this problem, your input w ...

  • 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