Question

HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...

HIMT 345
Homework 06: Iteration
Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes.
Prior Task Completion:
1. Read Chapter 05.
2. View Chapter 05’s video notes.
3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip.
Important: Do not skip the process of following along with the videos. It is a very important part of the learning process!
Specifics: PyCharm’s “Introduction to Python” project contains several examples of iterations or looping (see list at right). Follow the instructions to complete them. (Not handed in.)
Use PyCharm to work along with the video solution for Exercise 5.1 from the textbook. Type in the statements and execute the program as is done in the video. [Create a project and save your work as “Worked_Exercise_5.1”. It will prove valuable for part a below.] (Not handed in.)
Create a new PyCharm project called “Hwk06_<your last name>”. Create two new python files within that project called “Hwk06a_<your last name>” and “Hwk06b_<your last name>”.
Part (a): Let’s write the code to prompt the user for (an integer) blood-sugar reading (BSR) and print a warning message if it is over 500. Also, print the message “>> Invalid input” if the user enters a non-integer, such as a float or a string.
Having completed Worked_Exercise_5.1 above you should use that code as the basis for this problem.
Use this sample interaction to demonstrate your code:
Enter a BSR: 155
Enter a BSR: string input
>> Invalid input
Enter a BSR: 522
** Warning! Blood sugar reading over 500: 522
Enter a BSR: 485
Enter a BSR: 578
** Warning! Blood sugar reading over 500: 578
Enter a BSR: 210
Enter a BSR: 330.6
>> Invalid input
Enter a BSR: 519
** Warning! Blood sugar reading over 500: 519
Part (b)
Create a list of BSRs as follows:
blood_sugar_readings = [155, 190, 522, 485, 578, 210, 130, 519]
Use a for-loop to iterate through the list in order to find the highest and lowest BSR values. Note that finding the maximum and minimum values of a list using a for-loop is shown in Section 5.7.2 of the textbook on p. 62-3. (Note that since we are ‘hard-coding’ the list, we may assume the data is valid, i.e., it has been previously checked.)
HINT: as is done in the textbook, while developing the code, add a print statement as the last line of the for-loop writing out the current BSR value, the smallest, and the largest. Then when your code is running correctly, you can comment out that line (but leave it in the code-base).
After looping through the list, print the highest and lowest BSR values.
What to hand in:
Take screen snips of the Run window for Parts (a) and (b). Use the snipping tool on the console portion of the screen – but including the header bar and the file name.
Copy the snips into a Word document (filename Hwk06_YourLastName_ScreenSnips.doc) with your name and date in the upper right hand corner.
Upload the Word doc and the Python program files Hwk06a_YourLastName.py and Hwk06b_YourLastName.py to the appropriate assignment in the LMS. Three files total.
NOTE: As was described in the previous assignment, each Python file you create should be documented with (minimally) the following three lines at the top of each file:
# Filename: Hwk06_YourLastName.py
# Author: <Your Name>
# Date Created: 2017/09/05
# Purpose: <brief description>

Homework Answers

Answer #1

def checkBSR(val):
    if(val > 500):
            print("** Warning! Blood sugar reading over 500:{}".format(val))

        


def checkBSRList(BSRlist):
    minNumber = 9999
    maxNumber = -1
    for i in BSRlist:
        minNumber = min(minNumber,i)
        maxNumber = max(maxNumber,i)


    print("max BSR value is {}".format(maxNumber)+" min BSR value is {}".format(minNumber))



if __name__ == "__main__":
    try:
        BSR = int(input('Enter BSR:'))
        checkBSR(BSR)
    except:
        print(">> Invalid input")
    
    blood_sugar_readings = [155, 190, 522, 485, 578, 210, 130, 519]
    checkBSRList(blood_sugar_readings)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python 3 Conversion and exception handling Create a function that asks the user to enter a...
Python 3 Conversion and exception handling Create a function that asks the user to enter a number and returns the number. * function name: get_int * parameters: prompt (string) * returns: int * operation: Use the "prompt" parameter as the parameter to an input() call in order to ask the user for a number. Convert the number to a int using the int() function and return this number from the function. but - If the user enters something that cannot...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters (hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 YOU WILL NEED THREE FUNCTIONS: the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) Call the functions and passing the arguments in the "main" function. Example: def main(): the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) main() ----- Testing the outputs of your code: 1 for the valid...
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter feeds. At a high level, your program is going to perform the following: Read in two files containing twitter feeds. Merge the twitter feeds in reverse chronological order (most recent first). Write the merged feeds to an output file. Provide some basic summary information about the files. The names of the files will be passed in to your program via command line arguments. Use...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking option entered by the user print("Enter 0 to 5 for following options: ") print("0-> Issue new ticket number.") print("1-> Assign first ticket in queue to counter 1.") print("2-> Assign first ticket in queue to counter 2.") print("3-> Assign first ticket in queue to counter 3.") print("4-> Assign first ticket in queue to counter 4.") print("5-> Quit Program.") tickets = [] #Declaring list to store...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...