Presentation is loading. Please wait.

Presentation is loading. Please wait.

Thinking about programming

Similar presentations


Presentation on theme: "Thinking about programming"— Presentation transcript:

1 Thinking about programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg

2 A geek joke

3 Operator Order The default evaluation order is
Negation – Exponents ** Multiplication and division *, /, //, % Addition and subtraction, +, - The default order can be changed By using parenthesis (3 + 4) * 2 versus * 2

4 Math Operator Order Exercise
What is the result of 2 + 3 * 4 + 5 Where would you add parentheses to make it clear what is happening first How do you change it so that happens first? How do you change it so that it multiplies the result of and the result of 4 + 5?

5 Questions about the lab?

6 Problem #1 Calculating Olympic Prize Money
The USOC pays Olympic athletes who win medals the following in prize money: Gold $25,000 Silver $15,000 Bronze $10,000

7 Calculating Olympic Prize Money
How much money did they pay? Total (46/29/29) *** Michael Phelps (4/2/0) Missy Franklin (4/0/1) Ryan Lochte (2/2/1) *** Treats a team medal as one prize, not multiple prizes.

8 Steps in solving this problem
Identify the prize money for each medal type (constant over each athlete). Obtain the number of gold, silver, and bronze medals for the athlete (different for each athlete). For each medal type, multiply the medal count with it’s prize amount. Sum these three values to get total money won Display total amount of money won

9 We can do that !

10 Calculating Olympic Prize Money (Summer Olympics)
The USOC pays Gold $25,000 Silver $15,000 Bronze $10,000 How much money did they pay? Total (46/29/29) Michael Phelps (4/2/0) Missy Franklin (4/0/1) Ryan Lochte (2/2/1)

11 Rules to Follow Always have a header comment block with a Title, Author, Comment, and Deadline See “Resources” page for Homework Submission Policy Take care of line wrap Good rule of thumb is not to have a line exceeding characters Can look at “Col” field at bottom of IDLE to see where you are at

12 Rules to Follow Put a comment on top of each chunk of code for the human # Get the input for number of medals from user Use a consistent style camelCase c_style_naming Use constants Every time you have a literal number (like 25000) GOLD_PRIZE_AMOUNT=25000


Download ppt "Thinking about programming"

Similar presentations


Ads by Google