1 / 11

CSC 131 - Introduction to Computer Science I

CSC 131 - Introduction to Computer Science I. Review Question for test 3. Devon M. Simmonds Computer Science Department University of North Carolina Wilmington Wilmington, NC 28403 simmondsd@uncw.edu http://www.uncw.edu/people/simmondsd/

kamil
Download Presentation

CSC 131 - Introduction to Computer Science I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 131 - Introduction to Computer Science I Review Question for test 3 Devon M. Simmonds Computer Science Department University of North Carolina Wilmington Wilmington, NC 28403 simmondsd@uncw.edu http://www.uncw.edu/people/simmondsd/ _____________________________________________________________ ..

  2. Strings • Answer the following questions. Where an error occurs, state how the error can be fixed. •  Assume: ch = “TEST”, ch1 = “A”, num1 = 7 • What does this code produce: print(chr(Ord(ch1))) • Which of the following is not an escape sequence: • \\ • \t • \r • \p • None of the above

  3. Strings •  Assume: num1 = 7 five = '5' • What does this code produce: print("There are " + num1 + " days in a week") • What does this code produce: print("I am multiplying 5 by 7 to get: ", five * num1) • What does this code produce: • num = input("Enter two numbers").split() • #The user enters: 1.5 4.0 • print(num[0] * num[1])

  4. Strings • What does this code produce: • a = "1234" • b = "4cats" • c = 12345 • x = "123".isdigit() • print(x) • y = a.isdigit() • print(y) • z = b.isdigit() • print(z) • w = c.isdigit() • print(w)

  5. Strings • 1. What does this code produce: • print("JohnGov".isalpha()) • print("John Gov".isalpha()) • print("John4Gov".isalpha()) • 2. What does this code produce: • x = "In the beginning God created the heavens and the earth." • print(x.startswith ("In the beginning")) • print(x.startswith ("in")) • print(x.endswith ("Earth")) • 3. What does this code produce: • print("To be or not to be".replace("be", "was")) • print("To be or not to be".replace("be", "was", 1))

  6. Strings • 1. What does this code produce: • x = "In the beginning God created the heavens and the earth." • print(x.find ("In the beginning")) • print(x.find ("in")) • print(x.find ("Earth")) • 2. What does this code produce: • x = "In the beginning God created the heavens and the earth. And the earth was …" • print(x.rfind ("In the beginning")) • print(x.rfind ("in")) • print(x.rfind ("earth")) • 3. What does this code produce: • x = "In the beginning God created the heavens and the earth." • print(x.count ("In the beginning")) • print(x.count ("in")) • print(x.count ("earth"))

  7. Lists • Write code to show four different ways to create a list of ten values. • Write code to search the list numbers for the value of variable x and the print a message indicating found or not found. • What does this code produce: x = [1,3,2,3,4,5,4,6,7,8,9] x.insert(2, 44) print(x) x.remove(4) print(x) print(x.pop(1), "---", x) print("To be or not to be, or not to be to be.".split("to"))

  8. Lists • Other topics • List slicing •  Copying lists

  9. Lists • Default arguments: How do these two functions differ? def add(x, lst = []): if not(x in lst): lst.append(x) return lst def add(x, lst= None): if(lst == None): lst = [] if not(x in lst): lst.append(x) return lst

  10. Files • How these functions work • open close, read, readline, readlines, write

  11. Qu es ti ons? The End ______________________ Devon M. Simmonds Computer Science Department University of North Carolina Wilmington _____________________________________________________________

More Related