e7 practice assignment

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

encourage image

There's no tags or description

Looks like no tags are added yet.

27 Terms

1
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

Yes. It runs through the for loop 6 times, with 0 + 0 + 0 + 1 + 1 + 1.
Print is also nicely closing everything.

2
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

Yes, it runs through all three numbers and since the end number is zero, the “ZeroDivisionError” catches it.

3
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

No. The range of the list would be (1,4) and since the three numbers have indexes “0, 1, 2".

When i = 3, trying to access AQI[3] throws an IndexError: list index out of range because valid indices for this list are only 0, 1, 2. Note that the except block only catches ZeroDivisionError, not IndexError

4
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

Yes. It runs through the command again, giving 0 + 0 + 0 + 1 + 1 + 1 = 3.

5
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

No. You cannot put a condition after else! In Python, it must be elif value < 50:, or just else:. Writing else value < 50: throws an immediate SyntaxError.

6
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

Yes. Else has a colon after it!

7
New cards
<p><u>From question</u> → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”</p><p><strong>Is this option correct Python syntax or no?</strong></p>

From question → “Select all the code snippets that correspond to correct Python syntax and which will run without raising an error.”

Is this option correct Python syntax or no?

Python does not have a log() function. Even if you imported math.log or numpy.log, Python standard lists do not support element-wise math directly like log([38, 45, ...]) (that's a MATLAB feature or a NumPy array feature). Running this gives a NameError (or TypeError)

8
New cards

What does a ; mean in MATLAB?

In MATLAB, a semicolon has two main uses:

  • Suppress Output: When placed at the end of a line or statement, it runs the code and saves the variable, but hides the result from appearing in the Command Window.

  • Row Separator / Command Separator:

    • Inside brackets for arrays or matrices, it separates rows.


9
New cards

What does i mean in Python?

In Python, i does not have a special built-in meaning or reserved status; it is simply a standard variable name.

10
New cards

Does MATLAB have +=?

No.

% Instead of x += 5,

x = x + 5;

11
New cards

When do you use “end” in MATLAB?

knowt flashcard image
12
New cards

Can you multiply lists in Python?

knowt flashcard image
13
New cards

Python:

ans = 5 % 2

1

14
New cards

Python:

ans = [0, 1, 0, 1] * 2

[0, 1, 0, 1, 0, 1, 0, 1]

Just repeats it!

15
New cards

Python:

ans = [0, 1, 0, 1] / 2

Error

16
New cards

Python:

ans = [0, 1] + [1, 0]

[ 0, 1, 1, 0 ]
Just concatenates (glues) together!

17
New cards

Python:

ans = [i+1 for i in range(5)]

[ 1, 2, 3, 4, 5 ]

Range includes everything BUT the last number, which is 6.

So (0,1,2,3,4) + 1 gives that

18
New cards

Python:

ans = 1 + '2'

Error

19
New cards

MATLAB:

ans = 5 % 2

Error OR 5

20
New cards

MATLAB:

ans = [0, 1, 0, 1] * 2

[0, 2, 0, 2]

21
New cards

MATLAB:

ans = [0, 1, 0, 1] / 2

[0, 0.5, 0, 0.5]

22
New cards

MATLAB:

ans = [0, 1] + [1, 0]

[1, 1]

23
New cards

MATLAB:

ans = [2, 3] .^ [1, 2]

[2, 9]

The .^ operator means element-wise exponentiation (power), NOT multiplication!

24
New cards

MATLAB:

ans = [2, 3] > [1, 2]

[1, 1]

  • Is 2 > 1? Yes (1 / true).

  • Is 3 > 2? Yes (1 / true).


25
New cards

MATLAB:

ans = 10:-2:2

[10, 8, 6, 4, 2]

The syntax start:step:end starts at 10, steps down by -2 each time, and stops at 2.

26
New cards

MATLAB:

ans = [138, 153, 147, 160]
ans(ans < 150) = 0


Logical Indexing

[0, 153, 0, 160]

It finds all values less than 150 (138 and 147) and replaces them with 0.

27
New cards

The highest value for an individual digit that can be used in the base-6 number system is

knowt flashcard image