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
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...
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...
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...
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...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...