Section 1

Preview this deck

import math

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 14, 2020

Cards (51)

Section 1

(50 cards)

import math

Front

To use many mathematical functions, you'd first use this statement

Back

i in range(1,11)

Front

This complete line would execute something below with values of i in inclusive range 1-10

Back

:

Front

The end of the first line of a new function definition should be this.

Back

f.write("hello")

Front

To output the word hello to an opened text file variable called f, use this.

Back

(x,y=10)

Front

This would be after a new function's name if it took 2 parameters called x and y and y had a default value of 10.

Back

l1 + l2

Front

This expression will return a new list, joining l1 and l2 in order.

Back

list(range(2,9,2))

Front

To create the list [2,4,6,8] without [] and with a single statement use this expression.

Back

else:

Front

If a test is not satisfied and something else should happen when that occurs, it begins with this.

Back

They're all indented the same amount

Front

To do more than one thing based on a conditional test, they must have this property

Back

=

Front

This operator is used to store a value in a variable

Back

l.sort()

Front

This statement will change a list of numbers called l so that its contents are reordered from smallest to largest.

Back

log10

Front

The function that would return 3.0 if called with 1000 as its parameter is this.

Back

[1, 2, 3]

Front

This is how you write a list of whole numbers 1 through 3 in order.

Back

while

Front

to keep executing something if a test is true, use this keyword

Back

s.isdigit()

Front

This expression returns whether all the characters in a string called s are numbers (0-9).

Back

float

Front

this type stores a number with decimals

Back

The exponent of e that the parameter is

Front

The log function returns this

Back

i in l

Front

To check whether an item i is in a list called l without using indexing, use this expression.

Back

l = s.split()

Front

This statement puts all substrings in a string called s separated by spaces in a list called l.

Back

s.upper()

Front

This expression returns a modification of a string called s where all characters are capitalized.

Back

f.close()

Front

To make sure a text file variable called f that you've sent info to can be opened for reading, use this.

Back

if __name__ == "__main__":f()

Front

To define what the "main" function is, called f, without calling it, use this.

Back

l = f.readline() akd

Front

This statement will put the next unread line in an opened text file variable called f into a variable called l.

Back

for n in l:

Front

To do something for each number n in a list called l without using indexing, start with this expression.

Back

Return

Front

This keyword is used to give back a value to the place that calls a function.

Back

print("%-12s%6d" % ("Mary",21))?

Front

This expression outputs Mary left-aligned in 12 characters followed by 21 right-aligned in 6 characters.

Back

Bool (boolean)

Front

To do something conditionally, there must be an expression or value of this type

Back

def

Front

This keyword is used to create a new function.

Back

2

Front

The expression "abcdef".find("cd") returns this.

Back

break

Front

this keyword can be used to terminate a loop without changing the condition it keeps checking

Back

for

Front

to do something a fixed number of times without using separate statements, this keyword is the most appropriate.

Back

Input

Front

This function takes a prompt and returns the string of characters the user entered

Back

s = ",".join(l)

Front

This statement creates a string called s by joining a list of strings called l and separates them with a comma.

Back

float

Front

To convert a string of characters that a user entered, to a number that might have decimals use this function

Back

i in range(99,0,-2)

Front

this complete line would execute something below with odd values of i in decreasing order from 99 to 1.

Back

//

Front

This operator returns how many times the number on the right goes in completely into the number on the left.

Back

s = f.read()

Front

This statement will put everything in an opened text file variable called f into a string variable s.

Back

if

Front

This keyword is used before a test to determine whether something should be executed

Back

==

Front

This operator checks whether two values are the same

Back

randint(1,6)

Front

To simulate rolling a die, use this expression

Back

l[2]

Front

This expression will return the 3rd item in a list called l.

Back

for item in l:

Front

To do something for each item in a list called l without using indexing start with this line.

Back

Print

Front

This function is used to output something.

Back

float

Front

When two whole numbers are divided with /, the result has this type

Back

elif

Front

To choose from more than two alternatives, ones that aren't first or last begin with this keyword

Back

str

Front

This type stores a sequence of characters

Back

int

Front

This type stores a number without decimals

Back

len(s)

Front

This expression returns how many characters are in a string called s.

Back

random.randrange(1,9,2)

Front

Without importing the specific function, use this expression to create a positive 1-digit random odd number

Back

f = open("names.txt","r")

Front

Before reading from a text file variable called f that should be used to read from names.txt, use this statement.

Back

Section 2

(1 card)

Front

Back