+ All Categories
Home > Documents > CS 100 Introduction to Computing Seminar September 23, 2015.

CS 100 Introduction to Computing Seminar September 23, 2015.

Date post: 05-Jan-2016
Category:
Upload: reginald-rich
View: 213 times
Download: 1 times
Share this document with a friend
35
CS 100 Introduction to Computing Seminar September 23, 2015
Transcript
Page 1: CS 100 Introduction to Computing Seminar September 23, 2015.

CS 100 Introduction to Computing Seminar

September 23, 2015

Page 2: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (1)

• A company has determined that its annual profit is typically 23% of total sales. Write a Python program that asks the user to enter the projected amount of total sales, and then displays the projected profit that should be made from that amount of sales. What are the inputs and outputs?

Page 3: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (2)

• What are the inputs and outputs?

Inputs: projected amount of total sales

Outputs: projected profit

• Develop an algorithm

Page 4: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (3)

• Develop an algorithm

Step 1: Introduce the program

Step 2: Ask for the amount of projected sales

Step 3: Record the user’s response for projected sales

Step 4: Calculate the projected profit

Step 5: Provide the user with the projected profit.

  Step 6: Stop

Page 5: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (4)

• Develop a flow chart

Page 6: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (5)

• Develop a flow chart

http://www.cs.sunyit.edu/~urbanc/cs_100_sep_23_1.pdf

Page 7: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (6)

• Develop source code

Page 8: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (7)

# Step 1: Introduce the program

print ("This program projects future profit based on projected sales. ")

# Step 2: Ask for the amount of projected sales

# Step 3: Record the user’s response for projected sales.

sales_total = float(input("Enter the projected sales: "))

# Continued on next slide

Page 9: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (8)

# Step 4: Calculate the projected profit (formula: sales * .23)

profit = sales_total * 0.23

# Step 5: Provide the user with the projected profit.

print ("The projected profit is " , format(profit, '.2f'))

# Step 6: Stop

Page 10: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (9)

• One acre of land is equivalent to 43,460 square feet. Write a program that asks the user to enter the total square feet in a tract of land an calculates the number of acres in that tract. What are the inputs and outputs

Page 11: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (10)

• What are the inputs and outputs?

Inputs: tract size in square feet

Outputs: number of acres

• Develop an algorithm

Page 12: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (11)

• Develop an algorithm

# Step 1: Introduce the program

# Step 2: Ask for the amount of square feet of the tract of land.

# Step 3: Record the user’s input for the tract of land.

# Step 4: Calculate the acreage ( tract_size / 43560 ).

  # Step 5: Provide the user with the number of acres.

  # Step 6: Stop

Page 13: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (12)

• Develop a flow chart

Page 14: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (13)

• Develop a flow chart

http://web.cs.sunyit.edu/~urbanc/cs_100_sep_23_2.pdf

Page 15: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (14)

• Develop source code

Page 16: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (15)

# Step 1: Introduce the program

print ("This program determines the acreage in a tract of land.")

# Step 2: Ask for the square feet in the tract of land.

# Step 3: Record the user’s input for the tract of land.

tract_size = input("Enter the number of square feet in the tract: ")

Page 17: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (16)

# Step 4: Calculate the acreage (tract_size / 43560).

acres = float(tract_size) / 43560

# Step 5: Provide the use with the number of acres.

print ("The size of that tract is" , format(acres , '.2f' ) , "acres.")

# Step 6: Stop

Page 18: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (17)

• A customer in a store is purchasing five items. Write a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total cost. Assume the sales tax is 7 percent What are the inputs and outputs?

Page 19: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (18)

• What are the inputs and outputs?

Inputs: 1. the price of item #1

2. the price of item #2

3. the price of item #3

4. the price of item #4

5. the price of item #5

Outputs: 1. the subtotal of the 5 items

2. the amount of sales tax (based on 7% of sales)

3. the total cost

Page 20: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (19)

• Develop an algorithm Remember: there are only sequential

instructions… you cannot use a "loop"

Page 21: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (20a)

• Develop an algorithm

# Step 1: Introduce the program

# Step 2: Ask for the price of the first item

# Step 3: Record the price of the first item

# Step 4: Ask for the price of the second item

# Step 5: Record the price of the second item

# Step 6: Ask for the price of the third item

# Step 7: Record the price of the third item

# Continued on next slide

Page 22: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (20b)

• Develop an algorithm (continued)

# Step 8: Ask for the price of the fourth item

# Step 9: Record the price of the fourth item

# Step 10: Ask for the price of the fifth item

# Step 11: Record the price of the fifth item

# Step 12: Calculate the subtotal cost of all 5 items

# Step 13: Calculate the sales tax amount (subtotal * tax rate)

# Step 14: Calculate the total (subtotal + sales tax amount)

# Step 15: Communicate the subtotal, sales tax, and total values

# Step 16: Stop

Page 23: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (21)

• Develop a flow chart

Page 24: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (22)

• Develop a flow chart

http://web.cs.sunyit.edu/~urbanc/cs_100_sep_23_3.pdf

Page 25: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (23)

• Develop source code

Page 26: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (24)

• Develop source code

http://web.cs.sunyit.edu/~urbanc/cs_100_sep_23_c1.html

Page 27: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (25)

• A cookie recipe calls for the following ingredients: 1.5 cups of sugar 1 cup of butter 2.75 cups of flour

The recipe produces 48 cookies with this amount of ingredients. Write a program that asks the user how many cookies he/she wants to make, and then display the number of cups of each ingredient needed for the user’s specified number of cookies.

What are the inputs and outputs?

Page 28: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (26)

• What are the inputs and outputs?

Inputs: desired number of cookies

Outputs: 1. the amount of sugar necessary

2. the amount of butter necessary

3. the amount of flour necessary

• Develop and algorithm

Page 29: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (27a)

• Develop an algorithm

# Step 1: Introduce the program

# Step 2: Ask the user for the desired number of cookies

# Step 3: Record the user’s input for the number of cookies

# Step 4: Calculate the cups of sugar needed

( ( cookies_desired / cookies_recipe) * 1.5 cups_of_sugar )

# Step 5: Calculate the cups of butter needed ( 1 / 48 * number of cookies)

( ( cookies_desired / cookies_recipe) * 1 cups_of_butter )

# Step 6: Calculate the cups of flour (2.75 / 48 * number of cookies)

( ( cookies_desired / cookies_recipe) * 2.75 cups_of_flour )

 

 

Page 30: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (27b)

• Develop an algorithm (continued)

# Step 7: Communicate the amount of butter, sugar,

# and flour needed to make the specified number of cookies.

# Step 8: Stop

 

Page 31: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (28)

• Develop a flow chart

Page 32: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (29)

• Develop a flow chart

http://web.cs.sunyit.edu/~urbanc/cs_100_sep_23_4.pdf

Page 33: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (30)

• Develop source code

Page 34: CS 100 Introduction to Computing Seminar September 23, 2015.

Let's Work on Some Programs (31)

• Develop source code

http://web.cs.sunyit.edu/~urbanc/cs_100_sep_23_c2.html

Page 35: CS 100 Introduction to Computing Seminar September 23, 2015.

Monday: Exam


Recommended