Write a function to get a non-empty string

Assignment Help Python Programming
Reference no: EM132661588

Practical - Coding Checkpoint 2 & Strings

Use Docstrings
Please watch the checkpoint 2 video lecture on docstrings before starting this work.
For each and ALL of your functions from now on, write a brief function docstring.

Functions

Note that a program that uses a function means we need a main function as well.
A good general principle is that you should never write programs that use only one function.
If you're using a function (like those asked for below), then you also want a main.
If you only have main, then you don't really need it (but there's nothing wrong with a program that's entirely in a main).
1. Print a line
Write a function that prints a line of 40 hyphens.

2. Is it even?
Write a function to determine if an integer passed into it is even.
Note: In prac 6 we did this for if the number was odd, so it's nearly identical.
Don't copy that code unless you need help. Remember, we should know this now... so notice if you don't know how to do what you've already done before...

3. Get Non-empty String
Write a function to get a non-empty string. That is, you should be able to enter any string as long as it's not "".
Use this in a program to ask the user for their name using your function...
Then use the same function for getting their birthplace, and then display a message like:

4. Hi Martin from New Zealand!
So, if you need to use the same function for getting two different things and you want the user to know what you're asking, then you might need a function that can be customised... which is one thing we use parameters for.

Lists

4. Number List
Write a program that asks the user for a minimum and maximum number, then generates a list of integers between those two numbers, then prints it:
The maximum number must be greater than the minimum.
Note: Never use variable names that are the same as Python built-ins,

5. Subject List
Write a program to ask the user for their subject codes until they enter a blank one.
(Are you getting good at spotting words like 'until' and recognising that's the indefinite iteration pattern?)
All valid subject codes contain 6 characters, so reject any invalid subject code and ask again if needed.
When you have a list of subject codes, print them in sorted order and tell them how many subjects they have.
Then, tell them if they are cool or not... In the lecture notes, we determine if a student is cool based on whether they do CP1401 :)

All Together Now

IT JCU are expanding into the coffee business, and of course they need a Python program to help them, and they need you to write it...
This program includes lists, functions, decision structures, repetition structures and the usual input and output.
As always, the point is to apply what you have learned in terms of "best practice" (as best you know to date) and use the most appropriate code constructs to solve the problem.
We want a coffee-ordering program with a menu, a fixed list of valid coffees to check user orders against, and to print the instructions for making the selected coffee.
Of course we want to be able to drink our coffee (virtually), and because some people can't decide, we'd like to be able to choose randomly from the menu.

In the functions lecture, Barista Lindsay showed you how to make coffee using 4 'functions'. This program will use those... so make sure you've watched that video.


As always, start with planning.
As you look at the description and the sample output, think about:
• nouns (variables)
• verbs (processing, functions)
• sections, including repeated tasks (functions)
• types (strings, lists, etc.)
You should see that each of the functions in the coffee making video will be a function :)
You should remember that main should "look like the whole program", that is, main should generally consist of function calls (high level overview tasks), and
You should be able to clearly follow how the program runs by reading just the main function. You should recognise that when you display the coffees and when you check for a valid coffee order, you're working with a list of valid coffees
Note: The instructions are not meant to be complete or perfect. They're simplistic.
You should write simple functions for each step (like in the video). E.g.

Strings

Please make sure you have watched the Strings lecture before completing this section.
In that lecture, you were shown what you need to know for these exercises, including good examples very similar to these tasks.

6. Processing Strings
First, let's see another quick example of using slicing and finding.
Suppose we have data like:
string ="Result = 95%"
and we want to extract just the percentage as a number.
If we know the format will be just like that, we can use:
value =int(string[-3:-1])
But what if it might be different, like:
string ="Final Score = 8%"
# or
string ="Relative Value = 178.3%"
In those cases, our overly-simplistic approach would not work.
Ideally, we need a robust way of extracting the data, based on the possibilities the string could be.
So, in this case, let's assume we want all of the characters between the = and the % (which would be true in all 3 of these cases).
One way to do this is to find the index of the space after the = and then slice all the characters from there to one before the end.
Since we did this in the lecture, the rest is up to you now...
Write a program that processes this list of strings (copy the data here) and prints the values you extract.
data_strings= ["Result = 95%", "Final Score = 8%", "Relative Value = 178%",
"Something else that's very important = 9.2%", "x = 42%"]

7. Date Strings
(From the lecture)
Write a program to get and display only the year from a date of birth stored as a string like "13/07/1995"
Add a little interest to your program, by asking the user for their DOB, then printing like,
DOB: 13/07/1995
You were born in 1995
You turn/ed 25 in 2020.

8. Subject Code Strings
The first 3 characters in JCU Subject codes always follow a definite pattern:
The first 2 characters are the discipline (MA = Maths, CP = IT, etc.) and the next character is the year level.
Who knows what the last 3 characters mean? :)
Write a program that asks for subject codes until the user enters a blank one...
Hey, sounds familiar... just copy what you've already got, BUT this question does not use lists, so you have to change it!
After they type each one, print what year it is and whether it's an IT subject.

Re-Revision Practice
Note: We do NOT want you whacking in functions that are poor design -
e.g. violating SRP like a function that calculates and prints.
Also, remember to include a main function if you use any other function in your program.
When you're practising, always follow best practice!

Input, Processing, Output

1. Write a program that calculates a new value based on an original value and a (percentage-like) increase or decrease.
Example:
• Original: 100, Change: 0.05, Result: 105
• Original: 50.5, Change: -0.1, Result: 45.45

Decision Structures

2. Ask the user for the time of day (0-23 hours) until they enter a negative.
Then print a list of all the hours and how many of them were after noon:
(This program is quite different from checkpoint 1)

3. Coffee orders made simple.
• Ask the user for white or black coffee
• Ask for their chosen size: small, medium or large
• Then print the cost: For Black, Small = $3, Medium = $4, Large = $5. White coffee costs $1 more per size.
• If a user makes a mistake with their order, just pick the more expensive option :)

Repetition Structures
5. Write a program to ask the user for a low value and a high value, then print all of the integers between those values inclusive and show the total of those numbers.

Attachment:- Coding Checkpoint.rar

Reference no: EM132661588

Questions Cloud

What would be great brand- or line-extension : Make a list of 3 of your favorite brands. What would be a great brand-, or line-extension that you would like to see developed as a new product?
Identify strategies for crm project implementation : Identify strategies for the CRM project implementation. Identify reasons contributing to the failure of the CRM implementation at Mashkin.
Can any firm beat amazon in the marketplace : Can any firm beat Amazon in the marketplace? If not, why not? If so, how can they best do so? How formidable a competitor is Google for Amazon?
Organizational behavior topics : What possible Organizational Behavior topics do you see in this story? Explain. What personality traits would be most needed for this type of work arrangement?
Write a function to get a non-empty string : Write a function to determine if an integer passed into it is even and Write a program that asks the user for a minimum and maximum number
Risk management and sales management : Identify cyber security risk components that may exist within your real or fictional company. A description of the plan for the salesforce,
Foundations of doctoral experience : The title of this course is Foundations of the Doctoral Experience. In your post this week, discuss what you believe are the two or three most important element
What are key features of one of the bonds : What are the key features of one of the bonds issued by your chosen company? Discuss how the bond's terms and collateral can affect the bond's interest rate.
Explain what is subsequent events : Explain what is subsequent events. List two audit procedures the auditor may use to obtain sufficient audit evidence if the event was adjusting

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