coursework-banner

CIS115 Programming Logic and Design Week Discussions

CIS115 Programming Logic and Design Week Discussions

 

Week 1 Discussion

PYTHON AS A SOFTWARE DESIGN AND DEVELOPMENT TOOL

Compare Python with other popular programming languages such as C# and Java. Discuss the advantages of Python as a software development tool.

 

CIS115 Programming Logic and Design

Week 2 Discussion

CONTROL STRUCTURES

Discuss the three types of control structures. Describe how any one of these control structures impacts your Python programs. Do any of these structures have to follow a specific order?

 

CIS115 Programming Logic and Design

Week 3 Discussion

REPETITION STRUCTURES

How many different repetition structures does Python support? What are the major differences between them?

 

CIS115 Programming Logic and Design

Week 4 Discussion

COMPLEX DECISIONS AND LOOPS

Describe how multiple decisions in selection control structures are achieved. Indicate what should be used for combined If statements. Are multiple decisions different from nested decisions? Explain your responses with code examples.

Describe the relationship between outer and inner loops. Include code examples.

 

CIS115 Programming Logic and Design

Week 5 Discussion

ARRAYS/LISTS

Describe the terminology array, element, and index. Give your own example of each.

 

CIS115 Programming Logic and Design

Week 6 Discussion

MODULAR PROGRAMMING

Explain the benefits of incorporating a modular design into a computer program. Would it be more efficient to write one large program? Why or why not?

 

CIS115 Programming Logic and Design

Week 7 Discussion

ADVANCED TOPICS IN PYTHON

Research python in industry. It is used in web design, scripting, networking, etc. How can using python help further your career? What are some advanced topics in programming you are interested to learn about?

 

CIS115 Programming Logic and Design

Week 1 Lab

Building a Registration Form and Pay Calculator in Python

Summary – Part 1

Create a program that allows a student to complete a registration form and displays a completion message that includes the user’s full name and a temporary password.

Summary – Part 2

Create a program that calculates a user’s weekly gross and take-home pay.

Deliverables

•2 source code Python files.  Paste code into the Word document. NO SCREENSHOTS OF CODE

•A Word document containing both source code and the screen print of the program outputs.

Lab Steps

Part 1 – Registration Form

Sample Output:

Registration Form

First Name: James

Last Name: Smithington

Birth Year: 1984

Welcome James Smithington!

Your Registration is complete.

Your temporary password is:James*1984

Specifications:

•             The user’s full name consists of the user’s first name, a space, and the user’s last name.

•             The temporary password consists of the user’s first name, an asterisk (*), and the user’s birth year.

•             Assume the user will enter valid data.

INPUT   PROCESSING      OUTPUT

firstName

last_name

birth_year           password=first_name+”*”+str(birth_year)         password

Part 2 – Pay Calculator

Sample Output:

Pay Check Calculator

Hours Worked: 35

Hourly Pay Rate: 14.50

Gross Pay: 507.5

Tax Rate: 18

Tax Amount: 91.35

Take Home Pay: 416.15

•             The formula for calculating gross pay is:

o             gross pay = hours worked * hourly rate

•             The formula for calculating tax amount is:

o             tax amount = gross pay * (tax rate / 100)

•             The formula for calculating take home pay is:

o             take home pay = gross pay – tax amount

 

•             The tax rate should be 18%, but the program should store the tax rate in a variable so that you can easily change the tax rate later, just by changing the value that’s stored in the variable.

•             The program should accept decimal entries like 35.5 and 14.25.

•             Assume the user will enter valid data.

•             The program should round the results to a maximum of two decimal places.

INPUT   PROCESSING      OUTPUT

hours

pay_rate              gross_pay = round(hours * pay_rate, 2)

tax_rate = 18

tax_amount = round(gross_pay * (tax_rate / 100), 2)

take_home_pay = round(gross_pay – tax_amount, 2)    gross_pay

tax_rate

tax_amount

take_home_pay

 

CIS115 Programming Logic and Design

Week 2 Lab

Even or Odd and Grade Checker in Python

Summary – Part 1

Create a program that checks whether a number is even or odd.

Summary – Part 2

Create a program that checks one’s letter grade.

Deliverables

•             2 source code Python files.  Paste code into the Word document. NO SCREENSHOTS OF CODE

•             A Word document containing both source code and the screen print of the program outputs.

Lab Steps

Part 1 – Even or Odd

Sample Output:

Even or Odd

Enter an integer: 20

This is an even number.

Specifications:

•             Use the selection structure.

•             Assume that the user will enter a valid integer

Part 2 – Grade Checker

Make sure to use the following criteria:

•             100 – 90: A   if

•             89 – 80: Belif

•             79 – 70: Celif

•             69 – 60: Delif

•             59 and below: F    else

Sample Output:

Grade Checker

Enter your grade: 88

You earned a B

•             Assume the user will enter valid data.

•             Selection structure needs to be used.

 

CIS115 Programming Logic and Design

Week 3 Lab

Title of Lab: Bill Calculator and Shipping Calculator in Python

Summary – Part 1

Create a program that calculates the number of bills needed for a given dollar amount.

Summary – Part 2

Create a program that calculates the total cost of an order including shipping.

Deliverables

•             2 source code Python files copied/pasted into a Word document

•             Screenshots containing the screen print of each program’s outputin the same Word document.

Lab Steps

Part 1 – Bill Calculator

Sample Output:

Bill Calculator

Enter number of dollars: 521

Hundreds: 5

Fifties:    0

Twenties:  1

Tens:  0

Fives:  0

Ones:  1

Continue? (y/n): y

Enter number of dollars: 99

Hundreds: 0

Fifties:    1

Twenties:  2

Tens:  0

Fives:  1

Ones:  4

Continue? (y/n): n

Bye!

Specifications:

•             The program should display the minimum number of 100’s, 50’, 20’s, 10’s, 5’s and 1’s that one needs to make up the specified number of dollars entered.

•             Assume that the user will enter a valid integer for the number of dollars.

•             The program should continue only if the user enters “y” or “Y” to continue.

Part 2 – Shipping Calculator

 

Sample Output:

Shipping Calculator

Cost of items ordered:  49.99

Shipping cost:          4.50

Total cost:             54.49

Continue? (y/n): y

Cost of items ordered:  -65.50

You must enter a positive number. Please try again.

Cost of items ordered:  65.50

Shipping cost:          7.86

Total cost:             73.36

Continue? (y/n): n

Bye!

Specifications:

Use the following table to calculate shipping cost:

Cost of Items     Shipping Cost

< $35.00               5% of cost of items

$35.00 – $54.99  9% of cost of items

$55.00 – $79.99  12% of cost of items

> $80.00               Free

•             If the user enters a number that’s less than zero, display an error message and give the user a chance to enter the number again.

 

CIS115 Programming Logic and Design

Week 4 Lab

Title of Lab: Multiplication Table in Python

Summary

This week’s lab is to create a simple multiplication table using nested loops and if statements.

Prompt the user for the size of the multiplication table (from 2×2 to 10×10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number.

Put a # after any even number in your table (odd numbers will have just a space/nothing after them).

Deliverables

•             A Word document containing both source code and the screen print of the program outputs.

Lab Steps

Sample Output:

The output should be something similar to the following.

What size multiplication table would you like? (2 – 10): 1

Invalid entry – Enter a number between 2 and 10

What size multiplication table would you like? (2 – 10): 15

Invalid entry – Enter a number between 2 and 10

What size multiplication table would you like? (2 – 10): 10

—MultiplicationTable(10 x 10)—

12345678910

—————————————————————————

1|12#    3      4 #    5      6 #    7      8 #    9     10 #

2|2#    4 #    6 #    8 #   10 #   12 #   14 #   16 #   18 #   20 #

3|36#    9     12 #   15     18 #   21     24 #   27     30 #

4|4#    8 #   12 #   16 #   20 #   24 #   28 #   32 #   36 #   40 #

5|510#   15     20 #   25     30 #   35     40 #   45     50 #

6|6#   12 #   18 #   24 #   30 #   36 #   42 #   48 #   54 #   60 #

7|714#   21     28 #   35     42 #   49     56 #   63     70 #

8|8#   16 #   24 #   32 #   40 #   48 #   56 #   64 #   72 #   80 #

9|918#   27     36 #   45     54 #   63     72 #   81     90 #

10|10#   20 #   30 #   40 #   50 #   60 #   70 #   80 #   90 #  100 #

Hints:

•             The outer loop will start each new row.

•             The inner loop will control the display of each column in the row.

•             Note that to keep the numbers right-aligned, there are different amounts of space before single digit numbers (those less than 10), double digit numbers (those between 10-99), and triple digit numbers (100).

•             The row labels can be added to your inner loop (note that there are different amounts of space required after the number in the row labels.

•             The column labels should use a separate loop(s) that run before the main outer loop.

•             You can continue printing on the same line using end=”” in your print statement. This will come in handy if you want to print several things on one line inside a loop. For example, assuming the value of name is Ada, the following will print “Hello Ada” on one line:

print(“hello “, end=””)

print(name, end=””)

Tips:

•             Start early!

•             Do the basic table first without worrying about spacing or lining things up, and don’t include row or column headings (add those later).

•             Once you get the numbers in the correct position, think about adding the proper amount of space before each number to line things up.

•             Once the columns line up, add the #/space for even/odd numbers.

•             Once the basic table is working, then add the row and column headings, and finally the main title.

•             Test as you go!

 

CIS115 Programming Logic and Design

Week 5 Lab

Title of Lab: Race Time Sorting in Python

Summary

Store the times into arrays called Chevy[ ] and Ford[ ]. Then list the winner of each pair, giving the number of seconds the winner won by. At the end declare which team won based on which team had the most wins.

Deliverables

•             A source code Python file.

•             A Word document containing both source code and the screen print of the program outputs.

Lab Steps

There are eight cars in each team called Chevy and Ford. One car from each team races its opponent on the drag strip. Read in the racing times for the eight Chevy cars and then read in the times for the eight Ford cars.

Sample Match:

—Input Chevy Times—

Enter time for Chevy Car 1: 5.4

Enter time for Chevy Car 2: 7.2

Enter time for Chevy Car 3: 4.0

Enter time for Chevy Car 4: 9.1

Enter time for Chevy Car 5: 5.8

Enter time for Chevy Car 6: 3.9

Enter time for Chevy Car 7: 6.2

Enter time for Chevy Car 8: 8.1

—Input Ford Times—

Enter time for Ford Car 1: 5.8

Enter time for Ford Car 2: 6.9

Enter time for Ford Car 3: 3.9

Enter time for Ford Car 4: 9.2

Enter time for Ford Car 5: 5.8

Enter time for Ford Car 6: 3.8

Enter time for Ford Car 7: 6.0

Enter time for Ford Car 8: 8.5

And the winners are:

Chevy by 0.4 sec

Ford by 0.3 sec

Ford by 0.1 sec

Chevy by 0.1 sec

Tie!

Ford by 0.1 sec

Ford by 0.2 sec

Chevy by 0.4 sec

And the winning team is: F O R D !

Specifications:

•             Accept the racing times for each of the Chevy cars into the array Chevy[ ].

•             Accept the racing times for each of the Ford cars into the array Ford[ ].

•             Then declare the wining car for each race, giving the winning time in seconds.

•             If the times are identical, then declare the race was a tie.

•             Finally, declare which team won the match, assuming a tie is possible.

 

CIS115 Programming Logic and Design

Week 6 Lab

Title of Lab: Playlistin Python

Summary

Create a program that will allow a user to add, list, and delete songs from a playlist.

Deliverables

•             A source code Python file.

•             A Word document containing both source code and the screen print of the program outputs.

Lab Steps

The program should be modular. For example, you will want to have an add_song(playlist) function, a delete_song(playlist) function, a display_playlist(playlist) function, a display_menu() function, and a main().

Sample Output:

Welcome to the Playlist Creator!

1. Add a song

2. List all songs

3. Delete a song

4. Exit

Enter a menu option: 2

1 :Let it Snow

2 :I Have a Dream

Enter a menu option: 1

Please enter the song: Love Bites

Love Bites was added to the playlist

Enter a menu option: 2

1: Let it Snow

2 :I Have a Dream

3 :Love Bite

Enter a menu option: 3

Which number to delete: 3

Love Biteswas deleted

Enter a menu option: 2

1 :Let it Snow

2 :I Have a Dream

Enter a menu option: 4

Have a great day!

Specifications:

•             The program should start with 2 songs in the playlist.

•             Don’t forget to include at the end of the program the code:

o             if __name__ == “__main__”:

main();

•             Use this code for the delete_song(playlist) function:

defdelete_song(playlist):

number=int(input(“Which number to delete: “))

if number<1or number>len(playlist):

print(“Invalid number\n”)

else:

song=playlist.pop(number-1)

print(song,” was deleted\n”)

print()

 

CIS115 Programming Logic and Design

Week 7 Lab

Title of Lab: Creating a GUI in Python

Summary

This week’s lab is to create a GUI in python and use the tkinter module

Use text boxes to retrieve the speed and time traveled (in minutes) from the user. From this calculate the distance traveled: distance  = rate * time

Deliverables

•             A source code Python file.

•             A Word document containing both source code and the screen print of the program outputs.

Lab Steps

Sample Output:

The output should be something similar to the following.

Hints:

•             The following code below is an implementation of a GUI to solve for miles per gallon. Use the code from the example below calculating miles per gallon, and modify it to display the distance traveled.

•             Instead of asking the user for miles driven and gas. You will need to ask for Time driving and Speed. You will also need to modify the formula.

importtkinter as tk

fromtkinter import ttk

defclick_calculateButton():

miles = float( milesText.get() )    # get miles driven from the miles textfield

gas = float( gasText.get() )        # get gas used from the gas textfield

mpg = miles / gas                   # do the math!

mpgText.set( round(mpg,1) )         # display the output

defcommand_exitButton():

root.destroy()

# create root window

root = tk.Tk()

root.title(“MPG Calculator”)

root.geometry(“280×150″)    # size of window

# create frame and add it to the root window

frame = ttk.Frame(root, padding=”10 10 10 10″)

frame.pack(fill=tk.BOTH, expand=True)

# create labels and textfields

ttk.Label(frame, text=”Miles Driven:”).grid(column=0, row=0, padx=5, pady=5, sticky=tk.E)  # display label in grid

milesText = tk.StringVar()

ttk.Entry(frame, width=25, textvariable=milesText).grid(column=1, row=0)

ttk.Label(frame, text=”Gas Used:”).grid(column=0, row=1, padx=5, pady=5, sticky=tk.E)

gasText = tk.StringVar()

ttk.Entry(frame, width=25, textvariable=gasText).grid(column=1, row=1)

# create a button and add it to the window

ttk.Button(frame, text=”Calculate”, command=click_calculateButton).grid(column=0, row=2, padx=5, pady=5, sticky=tk.E)

ttk.Button(frame, text=”Exit”, command=command_exitButton).grid(column=1, row=2, padx=5, pady=5, sticky=tk.W)

ttk.Label(frame, text=”MPG:”).grid(column=0, row=3, padx=5, pady=5, sticky=tk.E)

mpgText = tk.StringVar()

mpgEntry = ttk.Entry(frame, width=25, textvariable=mpgText, state=”readonly”).grid(column=1, row=3) # notice readonly!

 

 

CIS115 Programming Logic and Design

Week 3 Quiz   

Question 1  (CO 1) A web application runs

through a browser

via a command prompt

with a GUI

through another application

Question 2 (CO 3) Pseudocode and/or flowcharts are used in which of the following steps in program development?

Understand the problem

Plan and design the logic

Develop the logical solution

Desk-check the solution

Question 3 (CO 1) The following is an example of __________.

#!/usr/bin/env python 3

executable code

byte code

source code

a shebang line

Question 4 (CO 8) When an exception occurs while a program is running, __________.

the program crashes

an error message is displayed on the console

the program crashes and an error message is displayed

an error message is displayed but the program continues

Question 5 (CO 1) Given: x = 7 , y = 2 , z = 1.5

What is the value of new_num after the following statement executes?

new_num = x / y + z

2

4.5

5.0

3

 

 

CIS115 Programming Logic and Design

Week 7 Quiz   

Question 1 (CO 2) Which of the following is not a valid name in python?

last_name

lastName

last name

lname

Question 2 (CO 3) How many times will “Hello World” be displayed after the following code executes?

num=2

while num<10:

print(“Hello world”)

num+=2

2

12

5

4

Question 3 (CO 1) The following code contains an error, what type of error is it and what line number is it?

1 num=1

2 while num<4

3    print(“num = “, num)

4    num+=1

5 print(“The loop has ended”)

line 1, syntax error

line 5, runtime error

line 4, runtime error

line 2, syntax error

Question 4 (CO 2) After the following code executes, what will be displayed?

guess=50

if guess<20:

print(“Too low”)

elif guess>20:

print(“Too high”)

Too low

Too high

The numbers are equal

nothing will display

Question 5 (CO 1) Given: x=23, y=15

What is the value of new_num after the following statement executes?

new_num = x%y

1.5333333

1

8

0.533333

 

CIS115 Programming Logic and Design

Week 4 Course Project    

The Week 4 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details. Use this report (Links to an external site.) to complete this portion of the project.

Guess the number!

You will create a program that will ask the user to guess a number between 1 and 10. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does

 

CIS115 Programming Logic and Design

Week 5 Course Project    

The Week 5 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details. Use this report (Links to an external site.) to complete this portion of the project.

Guess the number!

You will add to the program you created last week. This week you will add input validation and a count to show how many guesses the user took before getting the correct number. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does

 

CIS115 Programming Logic and Design

Week 6 Course Project    

The Week 6 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details. Use this report (Links to an external site.) to complete this portion of the project.

Guess the number!

 

CIS115 Programming Logic and Design

Week 7 Course Project    

The Week 7 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details. Use this report (Links to an external site.) to complete this portion of the project.

Guess the number!

 

CIS115 Programming Logic and Design

Week 8 Course Project    

This week we will create a powerpoint presentation illustrating your Guess the Number game course project. You will create a narrated powerpoint presentation.  A video explanation on how to create a narrated powerpoint is here (Links to an external site.).  In addition, add one new feature to your Guess the number game. Feel free to add any new feature. Some ideas include: