CSC 110 Week 8 Notes
CSC 110 Week 8 Notes CSC 127A - 002
Popular in Introduction to Computer Science
CSC 127A - 002
verified elite notetaker
Popular in Computer Science and Engineering
This 8 page Class Notes was uploaded by Kate Jahaske on Friday October 14, 2016. The Class Notes belongs to CSC 127A - 002 at University of Arizona taught by Allison Osbourn in Fall 2016. Since its upload, it has received 12 views. For similar materials see Introduction to Computer Science in Computer Science and Engineering at University of Arizona.
Reviews for CSC 110 Week 8 Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/14/16
10/10/16 Value/Reference Semantics Variables that are int, float or Boolean, store values directly. If it is initially 20, and you reference it later as 3, it will be 3. Multi-counter problem: most_frequent_digit that returns the digit value that occurs most frequently in a number For example, 667896466, would return 6 as the most frequent number 1. def main(): 2. most_frequent_digit(123412344) 3. 4. def most_frequent_digit(number): 5. counters =  * 10 6. while(number > 0): 7. last = number % 10 # to get the last number 8. number = number // 10 # everything but the last number 9. counters[last] += 1 10. 11. biggest = 0 12. for i in range(0, len(counters)): 13. if(counters[i] > counters[biggest]): 14. biggest = i 15. return biggest 16. 17. main() Section attendance question: Section [x] [section points] [compute grade] A means the student was absent  N means they attended but did not do problems  Y means they attended and did problems  5 students per section, like 12345123451234512345 I.e. for student 1, their points would appear at 1, 6, 11, 16, 21, and 26 o To break this up, use student % 5 o Cap at 20 1. def main(): 2. file = open("sections.txt") 3. lines = file.readlines() 4. 5. for line in lines: 6. counts =  * 5 7. line = line.strip() 8. for i in range(0, len(line)): 9. points = 0 10. if(line[i] == 'y'): 11. points = 3 12. elif(line[i] == 'n'): 13. points = 1 14. counts[i % 5] += min(counts[i % 5] + points, 20) 15. print(counts) 16. 17. main() Week 8, 10/12/16 Continuation from Monday with the section points problem When debugging, use the print() function to see where you may have gone wrong by being able to see what the program is using The error in this case was that points Logical assertion Right after a variable is initialized, its value is known. o x = 3 In general, you know nothing about parameters values: o def mystery(a, b) o Is a == 10? Sometimes Assertions and loops After a loop, the loop’s test must be False At the start of a loop’s body, the loop’s test must be True Inside a loop’s body, the loop’s test may become False Sometimes: Things that cause a variable’s value to be unknown will often lead to a sometimes o Reading from input o Reading from random o A parameter initial value to a function If x == y Parameters: Sometimes While loop: sometimes If statement: never Out of if: sometimes Out of while: never If x == 0 Point a: always While loop: sometimes In if statement: never Out of if: never Out of while: sometimes Week 8, 10/14/16 Midterm 2 will be just as long as the previous test. Work on becoming quicker at identifying certain problem patterns to become quicker at coding. Assertion Next == 0 Prev == 0 Next == prev Example Point A Sometimes Always Sometimes Point B Never Sometimes Sometimes Point C Never Never Always Point D Sometimes Never Sometimes Point E Always Sometimes Sometimes Be sure to account for user input, which will always be unpredictable Always check your code! It is very important to test many different variants of your code to reduce errors, such as the last name “Null,” which in many programing languages, means “Nothing” and will return “Nothing” in place. Or the other example of the Mars Climate Orbiter, that crashed and burned due to a software bug that converts metric to standard units. TERAC-25 Radiation Therapy – Two people died because they received a fatal dose of radiation because of a software bug that mishandled a race condition, which refers to completing a certain task before starting another one. London Ambulance Service Failure on November, 26-17, 1992. The software was supposed to direct the closest ambulances to emergencies. However, it was not checked thoroughly and in 1992 when there was an influx of emergencies. The ambulances were sent to very strange places, such as sending one very far away or sending 4 ambulances to one location. Black Box Testing: looking at the specifications Testing the program does what the specs requires Tester has no access to the code o Sometimes they don’t even have to know how to code White Box Testing: testing after looking at the code Examine code for potential problems Makes sure codes meets specs Test driven development: Software engineering philosophy Test are written before the code is written This is because the start of a project takes the longest, and at the end of a project, deadlines are close and testing is often rushed. Unit test: verifies correctness of a small portion of code Integration test: verifies different small already tested program components that work together Regression testing: complete retesting of a modified program Stress testing: tests the behavior under peak user volumes Others: performance, security, usability and many more
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'