Zybooks L1 Flashcards
A computer program consists of instructions executing at one time. Basic examples are:
Input (program receives data from a file, keyboard, network, etc)
process (program performs computations on data (i.e. x+y)
output (program puts that data somewhere (screen, file, etc)
computational thinking
creating a sequence of instructions to solve a problem (algorithm)
interpreter
A program that executes computer code.
code
The text that represents a computer program
prompt
Informs the programmer that the interpreter is ready to accept commands.
line
A row of text.
assignment
A new variable is created by performing an assignment using the = symbol, such as salary = wage * hours * weeks, which creates a new variable called salary.
expression
code that return a value when evaluated; for example, the code wage * hours * weeks is an expression that computes a number. The symbol * is used for multiplication. The names wage, hours, weeks, and salary are variables, which are named references to values stored by the interpreter.
what is the purpose of variables?
to store values for future use
how are most python programs developed
by writing codes in files
text
output from a Python program using the built-in function print( )
string
Text enclosed in quotes is known as a string. Text in strings may have letters, numbers, spaces, or symbols like @ or #.
keeping output in the same line
input
# Including end=’ ‘ keeps output on same line
print(‘Hello there.’, end=’ ‘)
print(‘My name is…’, end=’ ‘)
print(‘Carl?’)
output
Hello there. My name is… Carl?
Any character, or multiple characters, can be used instead of a space character.
command print variables and multiple values
The value of a variable can be printed out via: print(variable_name) (without quotes around the variable name). A single output line may include multiple strings and variables separated by commas. A space character is automatically added between each.
newline character “\n”
output can be moved to the next line using this
Ex: print(‘1\n2\n3’
escape sequence
string that has a special meaning, like the newline character “\n”, that always starts with a backslash “". Other escape sequences exist, such as “\t” to insert a tab, or “\” to print an actual backslash character.
Any space, tab, or newline is called whitespace.
The input() function is used to read input from a user.
The statement best_friend = input() will read text entered by the user, and assign the result as a new string to the best_friend variable. The input() function causes the program to wait until the user has entered text and pushed the return key.
int() function
using whole numbers
Input prompt
Adding a string inside the parentheses of input() displays a prompt to the user before waiting for input and is a useful shortcut to adding an additional print statement line.
hourly_wage = int(input(‘Enter hourly wage: ‘))
runtime error
a program’s syntax is correct but the program attempts an impossible operation, such as dividing by zero or multiplying strings together (like ‘Hello’ * ‘ABC’)