Programming (Python)

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

boolean

A _____ is like a light switch. It can only have two values. Just like a light switch can only be on or off, a _____ can only be True or False

variable

A _____ stores a piece of data, and gives it a specific name. For example: spam = 5

length=3.5 width=1.55

Define two variables , one named length making it refer to 3.5 and the other named width making it refer to 1.55.

string

Each character in a ____ is assigned a number. This number is called the index.

number

Each character in a string is assigned a ____. This number is called the index.

index

Each character in a string is assigned a number. This number is called the _____.

==

Equal to (___)

max

For example, ___(1,2,3) will return 3 (the largest number in the set of arguments)

3

For example, max(1,2,3) will return _

temperature>90 and humidity<10

Given the already defined variables temperature and humidity, write an expression that evaluates to True only if temperature is greater than 90 and humidity is less than 10.

4

How many times will "Boo" print? def surprise(): print("Boo") for x in range(1, 5): surprise()

0, 1

In Python, we start counting the index from ___ instead of __

0, 0, 1

Python uses _-based indexing, in which the first symbol of the string occurs at position _ instead of _

# (both)

The __ sign is for comments. A comment is a line of text that Python won't try to run as code. It's just for humans to read.

max()

The ___ function takes any number of arguments and returns the largest one.

str()

The ___ method turns non-strings into strings!

Jon

What value is inside index 3 from the given list below? name = ["John", "Harry", "Jesse", "Jon", "Harry", "Harry"]

error: variable 'funtion' is not defined

What will be the output of the given code? def function(x, y): return x + y z = funtion(4, 5) print(function)

5

What will be the output of the given code? def study(x, y): return x + y * 2 study(1, 2)

[10, 20, 30, 40, 50, 60, 60]

What will be the output of the given code? sampleList = [10, 20, 30, 40, 50] sampleList.append(60) print(sampleList) sampleList.append(60) print(sampleList)

true

if is a conditional statement that executes some specified code after checking if its expression is __.

floats

in python, _____ are numbers with decimals.

**

in python, we use __ to indicate exponents.

quotes

the thing that separates strings from variables is that string needs to be in ____.

and, or, not

there are three boolean operators: ___, which checks if both statements are true, ___ which checks if at least one of the statements is true, and ___, which gives the opposite of the statement.

concatenation

Combining strings together like this is called _____. Let's try concatenating a few strings together now!

called

After defining a function, it must be ____ to be implemented. In the previous exercise,

print

____ simply displays your code in the console.

colons (if some_function(): returns True, then the indented block of code after it will be executed. In the event that it returns False, then the indented block will be skipped.)

Also, make sure you notice the ____ at the end of the if statement. We've added them for you, but they're important.

string

Another useful data type is the ____. A ____ can contain letters, numbers, and symbols.

seven=7

Assign 7 to a variable named seven.

!=

Not equal to (___)

len()

Let's start with ____, which gets the length (the number of characters) of an iterable object

colons

Make sure the if and elif statements end with ____

min()

____ then returns the smallest of a given series of arguments.

backslash

There are some characters that cause problems. For example: 'There's a snake in my boot!' This code breaks because Python thinks the apostrophe in 'There's' ends the string. We can use the _____ to fix the problem, like this: 'There\'s a snake in my boot!'

+

The ___ operator between strings will 'add' them together, one after the other. Notice that there are spaces inside the quotation marks after Life and of so that we can make the combined string look like 3 words.

or

The boolean operator __ returns True when at least one expression on either side of or is true.

not

The boolean operator ___ returns True for false statements and False for true statements.

and

The boolean operator ___ returns True when the expressions on both sides of and are true. For instance: 1 < 2 and 2 < 3 is True; 1 < 2 and 2 > 3 is False.

def

The keyword ___ at the beginning of a function signals that we are "defining" a function.

functions, header, def, name, parameters

_____ are defined with three components: The ____, which includes the ___ keyword, the ___ of the function, and any ____ the function requires.

monthlyPay

Which is the best identifier for a variable to represent the amount of money your boss pays you each month? 1. monthlyPay 2. MonthlyPay 3. 12_monthlypay

hours_worked > 40

Working overtime is defined as having worked more than 40 hours during the week. Given the variable hours_worked, write an expression that evaluates to True if the employee worked overtime.

'!!!!!'

Write a String constant consisting of exactly 5 exclamation marks.

len(name)

Write a code that will count how many items are inside the list name = ["John", "Harry", "Jesse", "Jon", "Harry", "Harry"]

name.count("Harry")

Write a code that will count how many times the name Harry appeared in the list name = ["John", "Harry", "Jesse", "Jon", "Harry", "Harry"]

name.remove("Jesse")

Write a code that will omit the name Jesse from the given list. name = ["John", "Harry", "Jesse", "Jon", "Harry", "Harry"]

profits==losses

Write an expression that evaluates to True if and only if the variables profits and losses are exactly equal.

senior_citizens = 0 non_seniors = 0 if age >= 65: senior_citizens += 1 else: non_seniors += 1

Write an if/else statement that compares age with 65, adds 1 to senior_citizens if age is greater than or equal to 65, and adds 1 to non_seniors otherwise

function

You might have considered the situation where you would like to reuse a piece of code, just with a few different values. Instead of rewriting the whole code, it's much cleaner to define a _____, which can then be used repeatedly.

comment

You probably saw us use the # sign a few times in earlier exercises. The # sign is for comments. A ____ is a line of text that Python won't try to run as code. It's just for humans to read.

if

__ is a conditional statement that executes some specified code after checking if its expression is True.

Boolean operators

___ ___ compare statements and result in boolean values.

control flow

___ ____ gives us this ability to choose among outcomes based off what else is happening in the program.

string methods

___ ____ let you perform specific tasks for strings. We'll focus on four string methods: len() lower() upper() str()

elif

___ is short for "else if." It means exactly what it sounds like: "otherwise, if the following expression is true, do this!"

modulo

____ returns the remainder from a division. So, if you type 3 % 2, it will return 1, because 2 goes into 3 evenly once, with 1 left over.

functions, header, def, name, parameters, body

_____ are defined with three components: The ____, which includes the ___ keyword, the ___ of the function, and any ____ the function requires. The last is the ___, which describe the procedure the function carries out.

functions, header, def, name, parameters, comment, body

_____ are defined with three components: The ____, which includes the ___ keyword, the ___ of the function, and any ____ the function requires. The second is an optional ___ which explains what the fucntion does. The last is the ___, which describe the procedure the function carries out.

function

_____ are defined with three components: The header, which includes the def keyword, the name of the function, and any parameters the function requires.

function

a ____ takes an argument and returns an output.

input, output

a function takes an ___ and returns an ___

%

a modulo is represented by what between numbers?

=, ==

a symbol (___), in which we assign a value to a variable, and the symbol (___), in which we test the equality of two variables.

header, name, parameters

def hello_world(). Here the def is the ____, the hello_world is the ___, and there are no ___.

Function

def shout(phrase): if phrase == phrase.upper(): return "YOU'RE SHOUTING!" else: return "Can you speak up?" shout("I'M INTERESTED IN SHOUTING") This is an example of how a ___ is structured.

parameter

def square(n): n is a _____ of square. It acts as a variable name for a passed-in argument (the argument is the thing that will replace the parameter when you run the function)

header, comment, body

what are the three main parts of a function? Which one is indented?

index

what is this an example of: c = "cats"[0] n = "Ryan"[3]

4

when dealing with whitespaces, indent the code with the use of __ spaces.

=

you can assign a variable to a value with the operator __.


Kaugnay na mga set ng pag-aaral

Reflections of Exponential Functions

View Set

AIS Lynda Excel Tutorial Quizzes

View Set

ELC 401 Final (Completion Portion)

View Set

Organizational Behavior: Chapter 12 leadership

View Set

CIST 1130 Midterm Practice CH.2,4,7 & 8

View Set

Chapter 9 Teaching and Counseling

View Set