In: Computer Science
HIMT 345
Homework 05: Functions
Overview: Examine PyCharm’s “Introduction to Python” samples for
Functions. Use PyCharm to work along with exercises from Chapter 4.
Modify the grade assignment program of Hwk 04 to utilize a function
by copying the Hwk04 project and creating the Hwk05 project.
Prior Task Completion:
1. Read Chapter 04
2. View Chapter 04’s video notes.
3. As you view the video, work along with each code sample in
PyCharm. The examples used in the video are available for you to
experiment with if you downloaded the complete Severance source
files for Chapters 3-10.
a) With PyCharm open, locate the .zip file entitled Ch 4 Functions
PPT Code Samples.zip.
b) Open each of the project files for that chapter in PyCharm.
Note: The code samples are numbered in the order they are covered
in the video.
c) Start the video and follow along.
4. Complete Exercises 4.1 – 4.5 (not handed in).
Specifics: PyCharm’s “Introduction to Python” project contains
multiple examples giving the basics of conditional expressions (see
list at right). Follow the instructions to complete them. (Not
handed in.)
Use PyCharm to work along with the video solution for Exercise 4.6
from the textbook. Try to make the same mistakes (and fixes) made
by the author. (Not handed in.)
Create a copy of your Hwk04 project file, calling it Hwk05.
1. Highlight the Hwk04 project, select Refactor/Copy.
Important: Do not skip the process of following along with the
videos. It is a very important part of the learning process!
2. Give it a New name: of Hwk05 and leave the To directory: in its
default state.
Leave the “Open copy in editor” box checked.
3. After clicking OK, if the project fails to open, just open it
manually as you would
any project (File | Open | Hwk05 project).
You may immediately delete Hwk04b as it is not needed in this
assignment. You may
need to Refactor | Rename both the project name and the existing
Hwk04a.py file, as
only the directory was renamed by PyCharm in creating the
copy.
Having renamed Hwk04a to Hwk05_YourLastName.py, your task is to
determine the
letter grade using a function.
Here is some pseudocode* to guide the process:
(NOTE: The assign_grade function must be declared at the top of the
Python file.)
Prompt for the test score, using try-except to verify it is
valid
Invoke (call) the function, supplying it the test score and it
returning the appropriate
letter grade;
e.g. letter_grade = assign_grade(test_score)
Display the test score and appropriate letter grade.
What to hand in:
Take screen shots of the console window verifying correct handling
of bad input as well
as letter grades for one test score in each grade range. Copy the
screen shots into a
Word document (filename Hwk05_YourLastName_Screenshots.doc) with
your name and
date in the upper right hand corner. Upload the Word doc and the
Python program file
(Hwk05_YourLastName.py) to the appropriate assignment in the
LMS.
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: Hwk03.py
# Author: <Your Name>
# Date Created: 2016/09/05
# Purpose: <brief description>
(*) pseudocode: a notation resembling a simplified programming
language, used in
program design.
# Filename: Hwk05_YourLastName.py # Author: Your Name # Date Created: 2020/10/06 # Purpose: Learn about user defined function and try except in python def assign_grade(test_score): if test_score>90 : return "Ex" elif test_score>80 : return "A" elif test_score>70 : return "B" elif test_score>60 : return "C" elif test_score>40 : return "D" else: return "F" if __name__ == '__main__': try: test_score = int(input("Enter Test Score? ")) grade = assign_grade(test_score) print("Test Score {}\nGrade {}".format(test_score,grade)) except ValueError: print("Integer required")