01 Comments, Variables, Console Flashcards

1
Q

True or False: Python program code is executed line by line, from first to last line.

A

True

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

True or False: Every line of code, no matter what kind, is always evaluated left to right.

A

False
Expressions are evaluated left to right but assignments are evaluated right to left.

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

What expression/s are equivalent to this expression: a * b * c

  1. a * (b * c)
  2. b * a * c
  3. (a * b) * c
  4. c * b * a
  5. (a * b * c)
A

2, 3 and 5 are equivalent.

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

What expression/s are equivalent to this expression: a = b * c

  1. a = (b * c)
  2. b = a * c
  3. a = c * b
  4. c * b = a
  5. b * c = a
A

1 and 3 are equivalent

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

When it comes to coding styles, Python will…

  1. force you to follow a certain style.
  2. not force you to follow a certain style but there are recommentations.
  3. not force you to follow a certain style and there aren’t any recommendations either.
A
  1. not force you to follow a certain style but there are recommentations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why should programmers adhere to coding conventions and style recommendations?

A
  • easier maintainability
  • more consistency
  • easier understanding of someone else’s code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

For what parts are there style recommendations?

A
  • naming converntions
  • comment styles
  • formatting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are comments and how are they indicated?

A
  • comments will not be executed
  • used for documentation purposes
  • indicated by putting a # at the start of the comment
  • the # doesn’t have to be at the beginning of the line, the comment can start anywhere in a line
  • everything after the # will not be considered code and has no effect on the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the main data types used in this semester?

A
  • bool
  • int
  • float
  • str
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Choose the correct statement/s.

  1. a boolean data type can only store the values True and False.
  2. if I put the string “true” in a boolean data type, it works because Python is smart enough to automatically convert it into the value True.
  3. instead of True and False, I can also store the numbers 0 and 1.
  4. when creating a boolean variable, I always have to specify tell Python that the data type should be boolean.
A
  1. is correct
  2. is false. If you put a string into a boolean variable, it automatically becomes a string variable
  3. is false. If you put a number into a boolean variable, it automatically becomes a int/float variable. However, the boolean values True/False can be output in form of 0 or 1.
  4. is false. When creating a variable no data type is specified. Python assigns the data type according to the value that’s stored in the variable. Type Hints can be specified but they are only hints and aren’t enforced.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Choose the correct statement/s.

  1. Float numbers can easily be casted to the int data type without losing any information.
  2. If an int number is divided, it’s automatically transformed into a float number.
  3. Float numbers never have more than six decimal places.
  4. Float numbers are automatically rounded to the nearest integer when cast to an int data type.
  5. Int numbers can easily be casted to the float data type without losing any information.
A
  1. is false. If a float number is cast to the int data type, it loses its decimal information.
  2. is true.
  3. is false. They can practially have an infinite amout of decimal places.
  4. is false. They lose the decimal information and only the integer value is stored in the int data type.
  5. is true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Choose the correct statement/s.

  1. A string value can be created using either ‘ or “.
  2. You can use all basic mathematical operators on strings.
  3. “3” + “6” equivalents to “36”.
  4. “3” + “6” equivalents to “9”.
  5. Any boolean, int or float data type can easily be cast to a string without losing information.
A
  1. is true.
  2. is false. Only “+” and “*” can be used on strings.
  3. is true.
  4. is false. The two strings are only ‘pressed’ together, not added.
  5. is true.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which of the following statements are true for static typing and which are true for dynamic typing?

  1. Data type of variable is known at run time.
  2. Data type of variable itself is specified.
  3. Used by Java, among other languages.
  4. Example: x = 5
A
  1. Dynamic typing
  2. Static typing
  3. Static typing
  4. Dynamic typing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens in Python when a value is assigned to a variable that doesn’t exist yet?

A

the variable is created and the value is assigned to it

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

True or False: Variable names are case sensitive.

A

True

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

Which of the following variable names are valid by conventions and rules?

  1. 1st_name
  2. Keyword
  3. class
  4. first_variable_name
  5. test-variable
  6. mystring
  7. -type-
A
  1. invalid. variable names cannot beginn with a number.
  2. against convention. variable names should be in lower case.
  3. invalid. “class” is one of the reserved keywords and cannot be used.
  4. valid.
  5. against convention. words in variable names should be separated with an underscore.
  6. against convention. words in variable names should be separated with an underscore.
  7. invalid. variable names cannot beginn with an operator.
17
Q

What is the output of this code?

x = 13
y = x
x = 2 * y
y = 0
print(x)

A

26

18
Q

What is the output of this code?

x = 13
y = x
y = 0

A

There is no output, since there is no print()-function.

19
Q

What data type does the input()-function return?

A

String

20
Q

What is the output of this code?

x = 13
#x = 2 * x
y = 0
print(x)

A

13

21
Q

What is the output of this code?

x = 13
x = 2 # * x
y = 0
print(x)

A

2