Presentation is loading. Please wait.

Presentation is loading. Please wait.

REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.

Similar presentations


Presentation on theme: "REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS."— Presentation transcript:

1 REVIEW No curveballs this time …

2 PROBLEM TYPE #1: EVALUATIONS

3 Evaluate ExpressionOutputData Type 5 – 2 5 ** 2 “5” + “2” “5” * 2 5 / 2 5 // 2 5 % 2 5 + 2.0 5.0 * 2.0

4 Evaluate ExpressionOutputData Type 10 > 2 2 < 1 2 != 4 4 == 2 ** 2 ‘cat’ < ‘dog’ ‘cat’ < ‘Dog’ 5 > 2 and 10 > 11 5 > 2 or 10 > 11 5 > 2 and not (10 > 11)

5 Evaluate ExpressionOutputData Type str.lower(“HeLLo”) str.upper(‘HeLLo’) format(5.1, ‘.2f’) format(5.1, ‘10.2f’) format(5, ‘10d’) random.randint(1,5) len(‘cat’) len(‘cat’ + ‘dog’) not (5 > 2 and 5 < 4 )

6 PROBLEM TYPE #2: SHORT ANSWER

7 Short Answer – Sample Question ◦ Explain what a Boolean expression is and why you would use one while programming. Give an example in a short code.

8 Short Answer – Sample Question ◦ Identify two different functions that convert one data type to another. Then use each in an example code and explain when you would use it in an actual program.

9 Short Answer – Sample Question ◦ Explain how the “and” and “or” operators work. Write a short code to show an example of each and describe how you would use it in an actual program.

10 Short Answer – Sample Question ◦ What’s the difference between using an “ELIF” statement and a nested decision structure? Describe both individually and explain the difference between them.

11 PROBLEM TYPE #3: TRACE THE OUTPUT

12 Trace the Output #1

13 Trace the Output #2

14 Trace the Output #3

15 Trace the Output #4 …(1of 2) This problem was made by a fellow student. I figured I would include it here because it serves as good practice. This is only the beginning … see next slide for continuation.

16 Trace the Output #4 …(2 of 2)

17 PROBLEM TYPE #4: DEBUGGING

18 Types of Errors ◦ Syntax errors: the code does not follow the rules for the language; for example, a single quote is used where a double quote is needed, or a colon is missing, or a keyword is used as a variable name print ( “ Hello, world! ’ )

19 Types of Errors ◦ Runtime errors: in this case, your code is fine but the program does not run as expected (it “crashes”). For example, if your program is meant to divide two numbers, but the divisor is zero, a runtime error will occur. var1 = float( input (‘give me a number:’) ) number = var1 + 4 >> give me a number: seventeen thirty eight # runtime error

20 Types of Errors ◦ Logic errors: these can be the hardest to find. In this case, the program is correct from a syntax perspective, and it runs, but the result is not what you were looking for. For example, if your program prints “2 + 2 = 5” the answer is … clearly wrong. var = 3.49 print (var) >> 3.4900000000002

21 Types of Errors ◦ Please pay close attention this time around to naming the type of error that is being made ◦ Realize the most common error is a syntax error, at least when looking at the source code Example: x = 3 print(x + “4”) # this is considered a syntax error because you # are trying to add an integer to a string

22 PROBLEM TYPE #5: WRITE A PROGRAM

23 Write a program that … ◦ Asks the user for two random words. ◦ Sort the words in alphabetical order and print them out. ◦ Sort the words in size order and print them out.

24 Write a program that … ◦ Has the computer virtually roll two 6-sided dice. ◦ Output the result as follows: Virtual Dice Roll: 3 and 5

25 Write a program that …

26 ◦ Allows the user to qualify for a credit card. Requirements: -They must make at least $30,000 a year (disregard tax/deductions) -Their rent payment cannot be more than 50% of their total monthly salary -However, if they own their house, you do not need to take their monthly rent into account

27 Credit Card Qualifier: Sample Runs Credit Card Qualifier Annual Income: 40000 Do you own your house? (y/n): y You qualify! Credit Card Qualifier Annual Income: 40000 Do you own your house? (y/n): n Monthly Rent: 1200 You qualify! Credit Card Qualifier Annual Income: 50000 Do you own your house? (y/n): n Monthly Rent: 4000 Sorry, you do not qualify!

28 Write a program that … ◦ Allows a user to input the price of 3 items they are purchasing in a store ◦ Then, calculate and print out the subtotal ◦ Calculate the tax (assume 7%) ◦ Finally, print out the total bill ◦ You should format your numbers for money-talk

29 Write a program that … ◦ Allows a user to type in a 3 digit integer (assume, that the last digit will not be zero) ◦ Print out the original number ◦ Then, print out the number in reversed order Please enter a three digit number: 347 You entered: 347 347 backwards is 743

30 Write a program that … ◦ Asks the user to type in a 2 digit integer (assume, that the last digit will not be zero), and call it variable x ◦ Then, figure out variable y, which is number with the same digits as x but reversed order ◦ Then, print out x and y and their sum Please enter a two digit number: 25 25 reversed is 52 25 + 52 is 77

31 BEST OF LUCK!


Download ppt "REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS."

Similar presentations


Ads by Google