Exam 1 Flashcards

1
Q

If I have a file, testFile.py, what do I type in Command Window to run the file; if I use IDLE, what key do I press on the keyboard to run the file?

A

Python testFile.py; For IDLE, press F5.

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

What are the characteristics of machine language, assembly language, and high-level language?

A

Machine: 1s and 0s
Assembly: Symbols (Need an assembler)
High-level: Close to spoken language use complier or interpreter

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

Is Python a compiled or interpreted programming language? What’s the difference?

A

Python is interpreted programming language. Interpreted programming can do one line at a time.

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

Python interpreter can be used in two modes, what are they?

A

Interactive and script modes

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

Comments in Python begin with what symbol?

A

#

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

To display multiple items with a single print, you use ___ to separate items.

A

,

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

How to get input values from the user in Python? How to convert the input strings to numbers?

A

Input function always get a string. num=int(input(‘ ‘)), num=float(input(‘ ‘)).

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

Math operators in Python? Two types of division? Exponentiation? Remainder? Their order of precedence?

A

Order of Operations: (), **, *, /,//, %, +, -

Floating division: /
Integer division: //

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

Answer the following in order
16/3
16//3
16/(-3)
16//(-3)

A

5.333
5
-5.333
-6

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

What is 150 % 8

A

Use long division for this, the answer is 6

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

What are the data types learned in class?

A

int: integer
float: float
str: String
bool: Boolean

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

What are the restrictions for variable names?

A

Variable name cannot be a Python key word
Variable name cannot contain spaces
First character must be a letter or an underscore
After first character may use letters, digits, or underscores
Variable names are case sensitive

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

What is the assignment operator? Difference between = and ==?

A

= is the assignment operator. == on the other hand determines whether two variables are equal.

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

What is 1001011 in both decimal and hexadecimal?

A

Decimal is 71.0
Hexadecimal is 4B

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

Multiline continuation character in Python?

A

/

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

What does end=’delimiter’ and sep=’delimiter’ do?

A

end=’delimiter’: causes print to place delimiter at end of data instead of newline character.

sep=’delimiter’: causes print to use delimiter as item separator

17
Q

How to format output using the format function?

A

Format (area, ‘.2f’)

18
Q

What are the possible format specifications in print?

A

%.2f: float
%d: int
%s: str

19
Q

What are the possible escape sequences?

A

\n: new line
\t: tab

20
Q

What is a boolean expression? Relational operators and logical operators in Python?

A

Boolean Expression: Tests if a statement is true or false.

> : Greater than
<: Less than
=: Greater than or equal to
<=: Less than or equal to
==: Equal to
!=: Not equal to

21
Q

How do you access individual characters in a string?

A

StringV[0] -> len(StringV)

22
Q

You use what operator to concatenate strings?

A

+ operator

23
Q

What are the augmented operators in Python?

24
Q

How to get the substring of a string?

A

StringV[start:end:step]

25
Q

What are some other string methods?

A

isalnum: True if all characters in the string are letters or digits

isalpha: True if all characters in the string are only letters.

isdigit: True if all characters in the string are only numbers

islower: True if all letters in the string are lowercase

isspace: True if all characters are whitespace

isupper: True if all letters in the string are capitalized.