CS 103 Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

When a name (variable, function, etc.) is out of scope, there is no way to bring it into view in the current program True or false

False (a variable that's out of scope might come into view when a function is called and begins to execute. Or a running function may cloak another variable-making it out of scope- but it'll return to view when the function ends)

What statement is Python's counted loop?

The for loop

What is the difference between a function definition and a function call?

The function call is where the function is run again and again

What are the names of the 1st four columns (counting out from the binary point) in base 2?

The ones column The twos column The fours column The eights column

Global variables, which permit values to pass easily among different parts of the code, can be easily misused True or false

True

In MAPS, writing the code actually takes place somewhat late in the overall process True or False

True

In binary #s the columns in a number are "named" after the powers of 2 (ones, twos, fours, eights column) True or false

True

Python combines the need to identify the file (as operating systems sees it) with the step to open a file for use True or false

True

Python is an interpreted programming language True or False

True

Recursion can be useful as a way of supporting abstraction True or false

True

Recursion is useful in writing code because it can shorten the words needed to say the same thing True or false

True

The default Python way of handling files is to treat all input and output as text True or false

True

When testing a program it's okay to use input data that you know won't work True or False

True (you should use both valid and invalid data in testing. A successful test is one in which you correctly predict the outcome)

How many binary values are there? What is each binary digit called?

Two values, 0 and 1. Each digit is called a BIT

When proceeding through MAPS and moving from psuedocode to Python source code, is it permissble to move back a step?

Yes, it's fine to move back and forth as much as needed. Main idea is to avoid getting stuck.

Name one advantage of writing functions in programs

You write it once, call it many times Support abstraction in your code Provides for modularity A function can be improved later (All the code that uses this function benefits without changing this calling code)

What is the type of -5.1

float

To avoid a variable name from cloaking another variable name, it's a good idea to use different names for the _____ parameter and the _____ actual parameter

formal;actual

What are the 3 scalar types in Python and their operators?

1.) Int(integer) values from min. to max. and has operators such as + - * / // % 2.) Float (real values) values from min. to max. and has operators such as + - * / 3. Bool (boolean) values True and False and has operators such as and or not

What is a computer?

A digital electronic device that operates under the control of a stored program to process data into information

Recursion means what?

A program or function that is self-referencing

What is an algorithm?

A specific set of ordered finite steps to follow that ensured the solution to a problem

Program functions have both function definition and a function call. Values are passed to the function using formal parameter and actual parameter. Which parameters are used in funcion call?

Actual parameters

Match the names with a significant contribution that individual made to computing Alan Turing Grace Hopper John von Neumann

Alan- concept of Turing Universal Machine Grace- concept of high level languages so programming would be easier John- concept of the von Neumann architecture ( it is the underpinning of all modern computers)

Name 3 basic Boolean operations:

And, Or, Not

What does it mean for an object in Python to be iterable?

Being able to step through or count over all of the elements of that object

For the Boolean AND (conjunction) operation, which of the following is correct?

Both of the inputs must be true for the result to be true

State the 4 parts of computer hardware

Central processing unit (CPU) Memory Input units Output units

For the Boolean OR (disjunction) operation which of the following is correct?

Either one of the inputs must be true for the result to be true

Given the factorial function in code, since the program's specification states: ''' factorial function input: a positive integer output: returns the factorial of the entered # ''' You should avoid testing it with negative numbers. • True • False

False

In programming, the assignment operation always moves to the right True or False

False

Inside the computer, recursion works faster than the same process written with iteration True or False

False (each recursive call involves a new instance of a function)

The main point of CS 103 is to learn programing in Python True or False?

False (to learn algorithmic thinking)

Built-in Python list type functions such as remove() or insert() can be applied to objects of data type tuple True or false

False (tuples are immutable)

The primary reasons computers use binary numbers is because it's easier for humans to understand True or False

False, we use binary for reliability more than for convenience

Which of the following data types in Python isn't a structured type? o Tuple o List o Float o Tuple

Float

What is an alias in regards to computer programming?

Having more than one name or way to reach the same location in memory

What is "scope" as it relates to writing computer programs?

How far a variable or name can be "seen"

Which of the following Python structured data type is mutable? Strings Tuples Ranges Lists Dictionaries

Immutable immutable immutable mutable mutable

All of the following are good reasons for using functions when programming except for which one? Using functions supports modularity A function, once written, can be called over and over It makes writing program code take longer Writing functions is a form of abstraction

It makes writing program code take longer

Which of the following is true about Python language?

It's great for beginner programmers but probably not suitable for large projects

Which of the structured data types in python is mutable?

List

What is the Python programming language named for?

Monty Python's Flying Circus, a British comedy group

Recursion involves a base case and a recursive call. But which of the following is the best answer? o Only one base case is allowed o The recursive call is optional o One or more base cases is possible o It's possible to omit the base case

One or more base cases is possible

Which of the following is more accurate? o Python is implicitly typed: it figures out a variable's data type from the data type of the value assigned to it o Java is explicitly typed, unlike python- you don't have to declare the data type of each variable Python's implicit typing makes it a type safe language

Python is implicity typed: it figures out a variable's data type from the data type of the value assigned to it

Given this example: Animal - "aardvark" What is the value of animal[6]? - A - D - K - R

R

Why do programmers like recursion?

Recursion can make our code elegant and simple to read Recursion can pack a lot of meaning into a few simple program statements Done well, recursion greatly promotes understanding of code meaning

What are the 3 basic code structures in Structured Programming?

Sequence Conditional Iteration

What are the 3 structures in Structured Programming?

Sequence, Conditional (If Statement), Iteration (While and for loops)

What is the difference between = and ==?

The = is the assignment operator. It means MAKE the value to be what is shown. The == is the equality comparison operator. It ASKS whether the values match.

What statement is Python's logical loop?

The while loop

1+2 and 'mad'+'cap' are both allowed: what is this called?

This is an example of operator overloading. Python "knows what to do" based on the data types of arguments

Finding better algorithms to replace existing ones, and discovering new algorithms are what computer science is about True or false

True

When dealing with binary #s every additional bit doubles the size range (a 5 bit binary number has twice as many) True or false

True

A variable that is visible to all of the program code and all of the functions of that code is called what?

a global variable

Which way does assignment operate?

left

Python code to assign the value 5 to the variable n?

n = 5

Match the following punctuation symbols with the correct syntax for declaring structures type objects in Python. o myDict o myList o myString o myTuple

o myDict- { } o myList- [ ] o myString- " " o myTuple- ( )

When reading and writing files in a program you must ___ the file, then ___ the file, and finally ____ the file

open;use;close

What file access mode is the default?

read mode

What is each of the following file access modes? 'r': 'w': 'a':

read mode, used for getting data from the file write mode, used for sending data to the file append mode, used for adding more data to an existing file

Suppose we enter the following: o >>> n = input ("enter a number o >>> print (type(n)) o What is the type of n?

string

What is the type of 'mad hatter'

string

What is the type of 1<2

type is bool result is true

What is the type of 1/2

type is float result is 0.5

What is the type of 1+2.

type is float result is 3.0

What is the type of 1//2

type is integer result is 0

What is the type of 111%2

type is integer result is 1

What is the type of 1+2

type is integer result is 3

What is the type of 'mad' + 'cap'

type is string result is madcap

A data type is a set of _____ together with a set of _____ that work on them.

values;operators


Kaugnay na mga set ng pag-aaral

SPCE 680 - Chapter 10 Quiz (Goldstein - 2nd Edition)

View Set

Chapter 19- Gastrointestinal and Urologic Emergencies

View Set