cs 115 midterm

¡Supera tus tareas y exámenes ahora con Quizwiz!

what is the value of the result variable after the code below is executed? one = "1" two = "2" result = one + two result = result + "3"

"123"

CPU

(central processing unit) volatile. reads instructions from RAM, executes in order, instructions are simple, works with speeds as fast as RAM, relatively expensive component of a computer.

What are some of the guarantees for all selection control structures? one of the 2 branches is executed -both of the branches cannot be executed at the same time -they will not cause bugs -they have one entrance and one exit

-one of the 2 branches is executed -both of the branches cannot be executed at the same time -they have one entrance and one exit

what does the following output: 27 % 13

1

terabyte (TB)

1024 GB (~thousand libraries)

megabyte (MB)

1024 KB (~good sized book)

gigabyte (GB)

1024 MB (~good sized library)

petabytes (PB)

1024 TB (~ million libraries)

kilobyte (KB)

1024 bytes. (~one page typed text)

what does the following output: 1e4 + 1e5

110000.0 (also: 1.1e5)

Use this code to answer the question: if x>14: if x<17: print("green") elif x>25: print("blue") else: print("red") Question: which option will give the output of green? 15 and 16 no values of x 14, 15, 16, and 17 17 to 20 inclusive

15 and 16

what does the following output: 48 / (4 + 2) * 3

24.0

what does the following output: 7 ** 3

343

how many times does this loop repeat?: for i in range(5, 18, 4):

4

what does the following output: 19 // 3.0

6.0

what will be the values of the variable x during the execution of this code? x=9 y=x x="abc" x=y x=x+1

9 then "abc" then 9 then 10

what is the value of this expression: float(int("99"))

99.0

what is the output of the following code: print("Abby", 23, "Bob", sep="++") print("Carl")

Abby++23++Bob Carl

Use this code to answer the question: if x>5: print("A", end="") if x<=10: print("B", end="") else: print("C", end="") print("D") Question: if x has value 4, what is the output?

BD

Compiler v. Interpreter

Compilers are more thorough, generate faster executables and the executable is easier to distribute. interpreters are more dynamic, are easier to use in the development stage of a program, they also stop when they encounter a syntax error while compilers keep going if possible.

What is the value of the following expression? (choices are: False, also contradiction; False; True, also tautology; True) x == 8 or x == 18 (x has value 20)

False

What is the value of the following expression? (choices are: False, also contradiction; False; True, also tautology; True) x >= 5 and x <= 10 (x has value 17)

False

What is the value of the following expression? (choices are: False, also contradiction; False; True, also tautology; True) x < 5 and x > 10 (x any integer value)

False, also contradiction

what is the output of the following code: print("Jack", end="mm") print("Sam")

JackmmSam

Prolog

Purpose: what is the purpose of this program Pre-conditions: what is needed for this code to be executed (inputs) Post-conditions: what is the result of the program. (outputs)

What is the output of the following line of code? print("The answer is {:.4f}feet".format(12.3456789))

The answer is 12.3457

syllabus: goals

This course teaches introductory skills in computer programming using a high-level computer programming language. There is an emphasis on both the principles and practice of computer programming. Covers principles of problem solving by computer and requires completion of a number of programming assignments.

What is the value of the following expression? (choices are: False, also contradiction; False; True, also tautology; True) x < 100 or x > 10 (x any integer value)

True, also tautology

machine language

aka machine code. first language: binary. this is hard for humans to use so high level languages were developed.

Use this code to answer the question: if x>14: if x<17: print("green") elif x>25: print("blue") else: print("red") Question: which option will give the output of blue? 15 and 16 no values of x 14, 15, 16, and 17 17 to 20 inclusive x less than or equal to 14 all x's greater than 25 x between 17 and 25 inclusive

all x's greater than 25

how is an accumulator statement different from a regular assignment statement?

an accumulator statement has the same variable on the left and right of the assignment operator

fill in the blanks in the code so that the code is as efficient as possible in determining whether a number is less than 10, equal to 10 or greater than 10: if num > 10: print("greater") ____________: print("equal")) ___________: print("less")

blank 1- elif num == 10: blank 2- else:

A _______ is a mark on your program's code which tells the debugger where to pause execution

breakpoint

Guido van Rossum

creator of python,

runtime error

errors caused by the environment, bad input, non existent files-- usually found by the operating system.

semantics error

errors in meaning also known as logic errors. these are found by comparing results of test runs to expected results.

syllabus: late policy

homeworks/zybooks: accepted until 9 am the morning after for half credit, after 9 they aren't accepted at all lab assignment: lab work will not be accepted after the end of the period program implementations: lose 10% points possible per calendar day late (up to 5 days). if a program is turned in late you cannot get the bonus.

what is the meaning of the boolean variable var1 in this code? assume n is an integer: var1 = True if n % 2 == 1: var1 = False

if n is True, var1 is True, otherwise var1 is False

IDE and its components

integrated development environment. A set of tools that programmers use to. make programs in a nice GUI. Editor (lets you enter source code) translator (compiler or interpreter) shell/ command line window( for output and simple commands) debugger linker(combines your object code with library code to make whole program) loader (brings in finished executable code to memory so it can run)

is this a valid identifier (if not give reason why): 4me4u

invalid, cannot start with a digit

is this a valid identifier (if not give reason why): def

invalid, def is a keyword (reserved word)

what type does the // operator return?

it depends on the types of the numbers being operated on

What control structure is being used here: "Beat the cake mix 50 strokes"

iteration

you can assume the random library has been imported as from random import * . Write a statement that generates an integer between 7 and 35 inclusive. it is stored in a variable called my_rand

my_rand = randint(7, 35) my_rand = randrange(7, 36) *range doesn't include the end point, but randint does*

Use this code to answer the question: if x>5: print("A", end="") if x<=10: print("B", end="") else: print("C", end="") print("D") Question: for any value of x, is it possible to get output "ABCD"?

no, B and C cannot both be printed since they are in different branches of an if/else

pseudocode

not actual code, just the abstract of what you are doing, written as comments.

secondary storage devices (hard drives, DVD's, flash memory)

not volatile, slower, cheaper

what would this function call produce? choice("AEIOU")

one of the strings "A" "E" "I" "O" or "U" chosen at random

syllabus: plagiarism policy

plagiarism is not tolerated, you may work with one partner on program assignments but both partners must reference one another in their prolog. is a student uses help when writing code they must write that in their prolog.

syntax error

punctuation, spelling and grammar things. python is case sensitive so if you have something that doesn't match exactly with capitalization, that might be the error. These errors are found and reported by the compiler or interpreter.

you can assume the random library has been imported as from random import * . Write a statement that generates a floating point number between 0 and 1. Store it in a variable called rand1.

rand1 = random()

The expressions below are used in a for loop, as for i in ____________: which expressions below cause exactly 4 iterations? (4, no more, no less) range(10, 14) range(1, n+1) (assume n is 4) range(4) [5, 6, 7, 8, 9]

range(10, 14) range(1, n+1) (assume n is 4) range(4)

Regression testing says that you mist ___________ if you __________.

redo all test cases change your code

To find a semantics error, you must

run test cases with known outputs and compare the program's output to the correct values.

What control structure is being used here: "if there is a traffic jam, turn left, otherwise go 2 blocks straight ahead"

selection

What control structure is being used here: "get the price of the two items, then add 10% then display with 2 decimals"

sequence

comments

simple form of documentation. documentation is text that you as the programmer writes to explain to someone else what your program is doing. these are for other people not for a computer. languages ignore comments. Who reads them: other team members, the programmer who gets the job of maintaining your code after you left a company, yourself, your TA. explain WHY you did something, not to explain HOW.

regression testing

start over with the first test case and run all the test cases again after editing your code.

Name the three arrows that are used to control what happens in a debugger

step into, step over, step out of

algorithm

steps to solve a problem, same as the design

in this english sentence, The studnt is young, is that a syntax or semantics error?

syntax (spelling of student)

if a translator finds an error in your program, it is what type of error?

syntax (translator doesn't find semantics errors)

test plan

the test cases we use to test if our code is running correctly (can help us find semantic errors). The columns of a test plan are: description (what we are testing: normal cases, boundary cases, special cases, error cases), inputs, and the output you are expecting. These should be done by hand so that you know if you are getting the right output.

p > 25 or p < 100 p is a numeric variable with a value. what is the value fo the expression?

true, also tautology

is this a valid identifier (if not give reason why): Asmall1

valid

is this a valid identifier (if not give reason why): _thefirstone

valid

is this a valid identifier (if not give reason why): a_big_name

valid

RAM

volatile, fast, expensive

design

written in psudeocode. this is the step by step procedure of how to fix the problem or lay out your code. it should be ordered steps in english. this is an abstract view of what needs to be done.

high level language

written in words and abstract ideas (closer to the way humans think, requires translator, can run on many different kinds of CPUs)

Use this code to answer the question: if x>14: if x<17: print("green") elif x>25: print("blue") else: print("red") Question: which option will give no output at all? 15 and 16 no values of x 14, 15, 16, and 17 17 to 20 inclusive x less than or equal to 14 all x's greater than 25 x between 17 and 25 inclusive

x between 17 and 25 inclusive

Use this code to answer the question: if x>5: print("A", end="") if x<=10: print("B", end="") else: print("C", end="") print("D") Question: Which values of x would produce the output "ABD"

x is greater than 5 and less than or equal to 10

Use this code to answer the question: if x>14: if x<17: print("green") elif x>25: print("blue") else: print("red") Question: which option will give the output of red? 15 and 16 no values of x 14, 15, 16, and 17 17 to 20 inclusive x less than or equal to 14 all x's greater than 25 x between 17 and 25 inclusive

x less than or equal to 14


Conjuntos de estudio relacionados

Central Nervous System Stimulants

View Set

Chapter Exam (1)- Basic Principles of Life and Health Insurance and Annuities

View Set

RI&INSUR Ch. 9 Legal Principles Test 1

View Set

Chapter 8: Assessment Techniques

View Set

Nutrition Chapter 15: Life Cycle Nutrition: Toddlers through the Later Years

View Set

MCAT BIOCHEM Chapter 4 Amino Acids

View Set