New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

CSC 110/127A Midterm 1 Study Guide

by: Kate Jahaske

CSC 110/127A Midterm 1 Study Guide CSC 127A - 002

Kate Jahaske

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

This goes over lectures 1 through 10
Introduction to Computer Science
Allison Osbourn
Study Guide
Computer Science
50 ?




Popular in Introduction to Computer Science

Popular in Computer Science and Engineering

This 8 page Study Guide was uploaded by Kate Jahaske on Friday September 16, 2016. The Study Guide belongs to CSC 127A - 002 at University of Arizona taught by Allison Osbourn in Fall 2016. Since its upload, it has received 142 views. For similar materials see Introduction to Computer Science in Computer Science and Engineering at University of Arizona.

Similar to CSC 127A - 002 at UA

Popular in Computer Science and Engineering


Reviews for CSC 110/127A Midterm 1 Study Guide


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: 09/16/16
CSC 127A/110 Midterm 1 Instructor: Allison Obourn  Notes Notes can be made using a "#" or three single quotes ''' surrounding a note '''  Print The print function is used to print out a string of text in your program. 1. def main(): # always have a main function 2. print("Hello world!") # Encapsulate a string with parentheses () and quotes "" 3. 4. main() # Don't forget to call main The output will be: Hello world! For the above program.  "this is a legal string"  'this is a "legal" string'  """this is a legal string across more than one line""" Escape sequences can be used in a print string to do the following:  \t tab character  \n new line  \" double quotation mark  \\ backslash o To show a backslash in a print statement, you must use a double \\ otherwise it will be an invalid escape sequence  end="" or end='' will also create a new line  Functions Functions contain information within one call within main. Function syntax: 5. def main(): 6. name() 7. 8. def name(): 9. statement 10. 11. statement 12. main() In the name of the function, separate multiple_words with an underscore. Functions can be called within other functions as well.  Operators: combine multiple values or expressions. o + addition o - subtraction o * multiplication o / division o // integer division (no remainder) o % modulus (remainder) o ** exponent We will be given expressions to solve. Remember PEMDAS when solving them. Left to right, Parentheses, Exponents, Multiplication and Division, Addition and Subtraction  Number typing o A conversion from one type to another. This will truncate a double from a real number to an integer o Int = integers o float = real numbers  Variables Name = expression  zipcode = 90210  myGPA = 1.0 = 2.25 Note: For formatting, always use lowercase at the beginning of a sentence and use underscores if it is more than one word. Once given a value, a variable can be used in expressions: X = 3 Y = 5 * x – 1 X = "hello" You can assign a variable more than once as well. The program will run top to bottom and will use the most recent variable assigned. The exception to this is with functions. Assignment uses "=" as an assignment operator, not an algebraic equation. It will mean to Python, "store the value at right in variable at left." X = 3 X = x +2 This will become 5, and will then use 5 in the future. You can also use these commands in combination with your strings for your variables: 1. veg = "potatoes" 2. veg[3] # to print out "a" 3. 4. veg[10] # will print out an error 5. veg[-31] # will also print out an error 6. 7. veg[4:5] # will only print out "t" 8. veg[4:6] # will print out "to" 9. # this is because the last number is not included 10. # just like in for loops 11. 12. veg[:4] # will print the begining up to "t" 13. # output wil be "pota" 14. 15. veg.find("to") # output will be 4 16. # if there is no "to" it will not print out 17. 18. veg.upper() # output: "POTATOS" 19. veg = veg.upper() # output will be upper from now on 20. 21. veg # will print out what has been assigned  For loops For loop statement reduces redundancy. The for variable in range (start, stop). The start lets the function know when to start, and stop will be when to stop. Good times to use this are when what you want to print uses a pattern.  Set the variable equal to the start value  Repeat the following:  Check if the variable is less than the stop, if not, stop.  Execute the statements  Increase the variables value by 1. Print ("T-minus ", end=") For i in range (10, 0, -1): *Make sure to add the –1, otherwise the computer will continue counting down forever Print(str(I) + ", ", end=") Print() Print("Blastoff!") Print("The end.") Output: T-minus 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, Blastoff! The end. Nested loops, a loop inside of another loop. For i in range(1, 6): Five rows down For j in range(1, 11): 10 across Print("*", end"") Print() Output: ********** ********** ********** ********** ********** For i in range(1, 6): Five rows down. 1, 2, 3, 4, 5, 6 (last number, the stop number, will always be ignored) For j in range(1, i + 1): 1, and then (i + 1) across. Print("*", end"") Print() Output: * ** *** **** *****  Tables for Loops Using a table for your code is extremely helpful. Take the nested loop above as an example. The first loop is "i" and is how many rows you want the program to print. Follow the steps below to make a table: # of rows # of stars Difference in stars Line * 2 - 2 Line * 2 + size - 6 1 0 2 1 * 2 – 2 = 0 2 2 2 2 * 2 –2 = 2 3 4 2 3 * 2 – 2 = 4 4 6 2 4 * 2 – 2 = 6 5 8 2 5 * 2 – 2 = 8  Difference in stars is finding what is the difference between the lines. The difference in 1 and 2 is 2 stars. Same with 3 and 4 and 5 and etc.  Line is line * (the difference in stars) - or + what will get you to the original output. In this case it is – 2.  Size is replacing the – or + that got you the original output. If in this case size is 4, to return to – 2 you will have to subtract 6.  Constants Are a fixed value visible to the whole program. This is the only exception to be outside of the main function.  ALL_UPPERCASE_SYNTAX For example, size is a constant.  Parameters  A value passed to a function by its caller  Instead of line_of_7, line_of_13, write line.  Syntax:  Def <name> (<parameter>): <statemens>(s) Def say_password(code): Print("The password is: " + code) <name>(<expression>) for expression, add what you want for code in the above line Example: it passes the expression into the parameter: say_password(42) say_password(12345) Output: The password is: 42 The password is: 12345  A parameter in loops;  A parameter can guide the number of repetitions of a loop Chant(3) Def chant(times): For I in range(0, times): This starts at 0 and chant is 3. The range is 0, 3. This will output 3 lines as opposed to starting at 1. I.e. (1, 3) would only print out 2 lines. Print("Just a salad") Output: Just a salad Just a salad Just a salad Multiple parameters can be made as much as you want, as long as you separate them by commas. I.e. (height, width) Value semantics: when numbers and string are passed as parameters their values are copied  Modifying the parameter will not affect the variable passed in X = 23 Def strange(x): X = x + 1 Print("1. X = " + x) X will now be 24  Mystery parameters Follow the color coding below. 22. def main(): 23. major = "fred" 24. fred = "computer" 25. computer = "department" 26. department = "student" 27. student = "major" 28. 29. sentence(major, fred, department) fred, computer, student 30. sentence(student, computer, fred) major, department, computer 31. sentence("fred", "honor", computer) fred, honor, department 32. sentence("foo", "bar", "baz") foo, bar, baz 33. 34. def sentence(major, fred, foo): 35. print("Many a " foo + " in the " + fred + " of " + major) 36. 37. ''' 38. output: 39. 40. Many a student in the computer of fred 41. Many a computer in the department of major 42. Many a department in the honor of fred 43. Many a baz in the bar of foo  Math It is necessary to use from math import * to use the specific math functions listed in the slides. Simply calling a Python math function does not produce a visible result, to produce a visible output you must turn it into a variable: 44. from math import * 45. 46. def main(): 47. 48. result = floor(7.1) 49. print(result) 50. 51. main() The math functions min and max can be used to bound numbers. For example with an age, no one can be –3. For example, (0, -8) use the max function, as max will never be less than 0.  max (0, -5) To create a cap, use the min function. I.e. min(90, 104) will always select the lowest number, which can never be above the range we set as 90.  min (90, 104)  If/else These statements work the same way that they would in English. For example, "If it is raining, then I will bring an umbrella"  If it is raining = bring an umbrella  Else = do not bring an umbrella Use exclusively if/if you require 0 more path/output. Use exclusively if/elif if you need 0 or 1 path/output. Use If/elif/else if you require exactly 1 path/output. The following will not be on the midterm:  Graphics  While loops  Everything from lecture 13 and above  Converting between decimal and binary numbers


Buy Material

Are you sure you want to buy this material for

50 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


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'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Kyle Maynard Purdue

"When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the I made $280 on my first study guide!"

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.