Calculating correct output values - programming fundamentals

Assignment Help Python Programming
Reference no: EM133952516

Programming Fundamentals

Learning Objectives

In this Workshop you will:

define functions that return results;

run unit tests to measure the correctness of some functions;

use randomness to control functions, to generate random poems

Task 1
Each week (week 1 to 8) you will be required to submit into Canvas your solution. Each submission will be marked out of 5. Task 1 will be the total of your best 6 submissions.

Theme: Functions

As well as taking input parameters, functions can return output results. In this tutorial, you will practice writing some of these 'fruitful' functions. Get expert-level assignment help in any subject.

To make it more interesting, We have some automatic unit tests that will test your functions to see if they are returning the correct results. So you can just run these tests to see what mark you will get for the workshop.

Function Puzzles
In this task, you are going to write six 'fruitful functions', and some automatic tests will be run to see if your function is calculating the correct output values. The tests are like a series of six small puzzles, and the functions you write are the solutions to those puzzles.

Download the function_tests.py file. Then edit that file and write the missing functions. After you have written or updated each function, run the file which will execute the test method for it - test_all() function to see how many tests you have passed or failed.

You get marks for documenting each of your functions (triple-quoted docstring inside each function).

Can you pass all 30 of the tests???
(Your score for this workshop is the number of tests you pass, divided by 6)
Crazy poetry [OPTIONAL - no marks]
If you finished those functions quickly, you might like to play with writing some simple Python functions that generate crazy poems. Like this:
funny clown leaves sad dog
funny clown shoots mad dog
sad dog eats black gown
funny clown leaves sad dog
Create a new Python program called poems.py Copy the following code into it.

This program generates crazy poems, using simple noun and verb phrases.

def line(n1, v1, n2):
"""Generates one line of crazy poetry."""
print(noun_phrase(n1), verb_phrase(v1), noun_phrase(n2))


def poem(lines):
"""Generates a crazy poem with 'lines' lines."""
for i in range(0, lines):
line(i, i + 1, 7 - i)

poem(4)

Your task is to write the noun_phrase(n) and verb_phrase(v) functions, so that they return an English phrase that will be used to build your poems.

The noun_phrase function should return a noun phrase (a name of an object, or something that describes an object), for example "Mad Dog Moody". Try to make some of your noun phrases rhyme, so that the output will be more like a poem.
The verb_phrase function should return a verb phrase (a doing word/phrase), for example "runs" or "runs far from".

The input number should control which phrase is returned. For example, if you want to have three different verbs in your poem, then each value of v (0, 1, 2) should return a different verb. Try to handle larger input values in a nice way too, so that your program doesn't crash. Hint: use an if statement, or the modulo operator (%) to limit the input number to your number of phrases.

After you've defined those two functions (make sure you add documentation strings!), run your program to see what poem you get?
Crazy poetry part 2 [OPTIONAL - no marks]

Here are some ideas for making more realistic/fun poems:
Change the code in the poem function so that it chooses random numbers to pass as inputs to each line? Or experiment with a mixture of random numbers and loop variable formulae (like 'i'). Hint: to generate a random number between x and y (inclusive), import the random library, then call random.randint(x, y).

Change the line function so that it doesn't choose the same input value for both noun phrases?
Change your noun_phrase function so that it returns some noun phrases more often than others, to get some repetition in your poem?

Go back to the earlier workshops where you wrote pseudo code for sorting M&M. Write a function that will sort and count M&M. Think about the data structure that you will store your original M&Ms (You might have to jump ahead to next week's module on Lists and Dictionaries.
Create a function that return counts the red M&Ms from a given input of M&Ms.
Create a function that return counts a given colour M&M from a given input of M&Ms.
Create a more general function that returns all the counts or all the colours from a given input of M&Ms.

Reference no: EM133952516

Questions Cloud

What resources were deployed for this incident : What resources were deployed for this incident? What protocols were implemented successfully during the incident, and which were unsuccessful?
Clinic receiving annual physical checkup : Leah Smith, an 87-year-old patient, is at the clinic receiving an annual physical checkup. The patient is wearing a sweater but complains that the room is cold.
Does having a distorted view of criminal justice matter : Many people rely on the media to inform their understanding of crime and criminal justice. Does having a distorted view of criminal justice matter?
Patient pain medication : How could Pharmacy have demonstrated more efficient teamwork with the nurse to get the patient's pain medication?
Calculating correct output values - programming fundamentals : ICT112 Programming Fundamentals, University of the Sunshine Coast - Create a function that return counts the red M&Ms from a given input of M&Ms
What did you notice that the therapist did well : What evidence from the literature supports the techniques demonstrated? What did you notice that the therapist did well?
What have you discovered about development of your research : What have you discovered about the development of your research topic and research problem? Do you need to get more familiar with qualitative studies in topic?
Reliable and valid method of measurement : When you develop a research project, you need to have a reliable and valid method of measurement in your study.
What processing technologies are being used : What processing technologies are being used to make these polymer products, and briefly describe the process?

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd