CHAPTER 1-3 Flashcards

0
Q

What is a programming language?

A

A method of communicating instructions to a machine in order for it to run/read a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

A computer program-

A

A list of instructions written by a software developer or coder that can be used/read/ran by a computer to perform specific tasks from the very simple to the compelex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is python different from other programming languages?

A

— is one of the easiest programs to learn and use. It doesn’t use quite as many complicated symbols as other languages and the symbols it does use aren’t used quite as often.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is IDLE (Integrated development envoronment or interactive DE) or Interpreter?

A

Is a software application used by programmers to build software- it comes with a source code editor, build automation tools, and a debugger.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a python Shell?

A

Another name for pythons IDLE application. It is built-in to your python program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a comand line interface (CLI) or for Mac OS- terminal?

A

— is a user interface to a computers operating system OS, or an application in which a user can test his code and get an immediate response. Most people prefer using their computers GUI rather than this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a prompt?

A

> > > (3 angle brackets) is the first thing you see in your python program if opened from your interpreter. This is the indication that your IDLE is awaiting your command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Statement.

A

At your Python interpreter prompt you are required to enter your command, in programming a complete command is called a —.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a function?

A

When at your python interpreter and you’re looking at your&raquo_space;> you’re required to enter a command, a — is a block of organized, reusable code used to perform a single specific action. Python has many of these built in, but you can create your own, these are called user-defined —s.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is PRINT?

A

Is a function used to reveal the value inside a variable. Note the p must be in lowercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you open your python interpreter or IDLE?

A

Simply enter its name at your command line interface or your Mac terminal. This will cause the appropriate application to pop up.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you save your python program and how do you run them?

A

Saving your — is easy, just use your MAC menu bar and to the only way to run your work is to have your code saved into a module you’ve created in your interpreter/IDLE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Variable = value. Explain.

A

A variable is like a box you put variables in, in mathematics every variable has its value or set of values, same in programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you solve 10/2 in your python IDLE shell?

A

> > > 10 / 2

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an integer?

What is a float?

A

1, 3, 2, 18, 299.

1.0, 3.0, 2.0, 1.8, 29.9. (Any number w/ decimal point)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a string?

A

A list of characters in order DECLARED in python by single quotes, double quotes, or triple quotes (‘, ‘’, ‘’’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a multiline string?

A

A string that has three quotation marks, it allows you to add in as many extra quotes within the string as you’d like withiut having to escape!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How would you ESCAPE an extra quotation mark in a string?

A

Using the backslash () before the quote is all you need if you have ONE extra quote. If you have two quotes then add another backslash () just before the the last quote WITHIN your strings two quotation marks.

18
Q

What is a List?

A

[ ‘one’, ‘two’, ‘three’ ]

___ are what you get when you get a collection of single variables brought together seperated by only commas and surrounded in SQUARE BRACKETS when the values are being assigned to a ___ variable.

19
Q

How would you tell python to print the 2nd item from this List?

> > > List1 = [1,2,3,4]
List2 = [‘apple’,’egg’,’milk’,’pie’]

A
>>> List1[2]
3
>>> List2[2]
milk
>>> print (List1[2])
3
20
Q

How would you tell python to print the first three items in the following list:

> > > List3 = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]

A
>>> List3 = ['a', 'b', 'c', 'd', 'e', 'f']
>>> print (List3 [1:4])
a, b, c
>>> List3 [1-4]
a, b, c

Note you aren’t just using the index positions as in ‘hey python print items 1-3,’ instead you’re printing starting with the first item index position and then stopping entering the index position of the number that comes after the last item you want to use!

21
Q

How would you change an item in a list?

> > > List3 = [‘a’,’b’,’c’,’d’,’e’,’f’]
How woukd you make this list read ‘absdef’?

A
>>> List3 = ['a','b','c','d','e','f']
>>> List3[2] = s
>>>
>>> List3
['a','b','s','d','e','f']
22
Q

How would you modify an item in a List?

> > > Numbers = [2,4,5]

A
>>> Numbers
[2,4,5]
>>> Numbers[1]
4
>>> Numbers[1] = 7
>>>
>>> Numbers
[2,7,5]
23
Q

Show how to give a variable a value and how you would unpack it.

A

> > > freds_age = 10
freds_age
10

24
Q

What are the following are how are they used in python?

( ),[ ],{ },< >

A

( ) - Parenthesis
[ ] - Square brackets
{ } - Curly brackets
< > - Chevron

25
Q

How would you modify an item in a Tuple?

> > > Numbers = (2,4,5)

A

Trick question. Unlike a List, you can not modify items in a ___, once they have been created!

26
Q

How would you tell python to print the 2nd item from this Tuple?

> > > Change = (‘p’,’n’,’d’,’q’,’D’)
Change = (.01,.05,.10,.25,1)

A

> > > Change(2)
d
Change(2)
.05

27
Q

How would you add 2 lists together so they appear on the same line or in the same variable?

> > > Numbers = [1,2,3]
Colors = [‘blue’, ‘red’, ‘yellow’]

A
>>> Numbers = [1,2,3]
>>> Colors = ['blue', 'red', 'yellow']
>>> 
>>> print (Numbers + Colors)
[1,2,3,'blue','red','yellow']
>>> SuperList = (Numbers + Colors)
[1,2,3,'blue','red','yellow']
28
Q

To add a new item to an already created list you use the APPEND function. How do you use this?

A

If you have this list
»> List4: [1,2,3,4,5]

And you wanna append 7 into the list you do:
»> List4.append(7)

> > > List4
1,2,3,4,5,7

29
Q

How do you delete an item inside a list?

For example, delete ‘d’ from following:
»> List5 = [‘a’,’b’,’d’,’c’]

INTRoDUcINg ‘del’

A
>>> List5 = ['a','b','d','c']
>>> del List5[2]
>>>
>>> print (List5)
['a','b','c']
30
Q

What is a Tuple?

A

Essentially a list that uses parentheses when first assigning its values.

31
Q

What is a {Map/dict}?

A

A ___ are like lists and tuples except they help you organize values and variables within a larger variable object. For example if you wanted to create a variable to store the top 5 athletes of all time and also give each athlete their sport as a value, you’d need this variable object.

It utilizes {curly braces} and colons :

32
Q

Give an example of a Map/dict in use.

How would you tell python to print the variable in one of those values?

A

> > > Sports = { ‘Jordan’:’basketball’, ‘Jeter’:’baseball’, ‘Tiger’:’golf’}Sports[‘jordan’]
‘basketball’

NOTE THAT YOU USE A LIST LIKE SQUARE BRACKET TO GET THE VALUES INSIDE A MAP!!!

33
Q

How is a [List] different from a (Tuple) besides the brackets they use?

A

A List item can be changed simply by giving it a different value, whereas items written in a Tuple can NEVER be modified.

34
Q

What is an index position as it relates to lists, tuples, or dicts?

A

The index position is the position in which an item is inside a list, tuple, or dict/map. The first item is always in the 0 index position the second item is in the 1 index position, and so on. So for example here:
»> List = [a,b,c]
»> # a is in the 0 index position, while c is in the 2nd index position.

35
Q

What is CONCANTeNaTIoN?

A

Addiding things

36
Q

What are the following:
Syntax Error- invalid syntax
EOL error
String literal or anonymous string

A

___ means the arrangement/ order of words in a sentence is wrong. Also could include symbol placement.

___ specifically tells you there is an error at ghe end of your code line.

___ or anonymous string is just another word for the value within a certain string. Foo would be the string literal in the string ‘Foo’.

37
Q

What are the following:
Exceptions- Traceback, Most recent call last
Operand types
Stdin

A

___ appear when there’s some mistake in a statement even if it’s syntactically correct.

___ ???

___ shows up when you are doing something fundamentally wrong in python. Like trying to open file_name.py in Terminal when you can only open this shell command in shel/IDLE.

38
Q

How do you embed values into a string using the % place holder/marker and how do you print it?

A
>>> myscore = 95
>>> message = 'I scored %s points'
>>> 
>>> print (message % myscore)
I scored 95 points
39
Q

Can you create a new variable with a placeholder marker desigbed into it? How do you then print a seperate variable into this new variable you created?

A
>>> Grade = '%s: subjects I did well in'
>>> Message = 'math, biology, chemistry'
>>> Message2 = 'art, history, gym'
>>> Print (Grade % Message)
subjects I did well in: math, biology, chemistry
>>> Print (Grade % Message2)
subjects I did well in: art, history, gym
---------------
>>> A = '%s: is the BESS'
>>> B = 'Khaled'
>>> print (A % B)
Khaled: is the BESS
---------------
>>> B = 'Khaled'
>>> print (%s: is the BESS % B)
Khaled: is the BESS
40
Q

How do you indent spaces?

A

To create spce you must create a variable that gives you blank spaces multiplied by whatever your desired space is:

> > > spaces = ‘ ‘ * 25

41
Q

How would you use what you know about placeholders/markers to create space in front of and just after the words Have a great day so that those words are in the middle of a page?

A

> > > spaces = ‘ ‘ * 10
Message = ‘Have a nice day’
print (‘%s Message’ %spaces)

42
Q

How would you create spacing like you would in a letter?

Hint (‘\n’)

A

You use the backslash (‘\n’) on each code line you want to ‘spacebar’.

> > > ‘Twas a evening to remember blablabla’
‘and then blablablablablablablablabla’
(‘\n’)
(‘\n’)
‘The night was dark and solemn blabla’