CS 1315 - Quiz 2

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

1/28

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:18 AM on 2/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

29 Terms

1
New cards

Integer (int)

A whole number without a decimal (e.g., 5, -23, 0).

2
New cards

int(15.9)

Results in 15. Casting to an int always truncates (chops off) the decimal.

3
New cards

Float

A number with a decimal (e.g., 5.0, 15.99, -2.3).

4
New cards

float(15.9)

Results in 15.9. Floats keep the decimal.

5
New cards

Standard Division (/)

Always results in a Float. 10 / 2 is 5.0.

6
New cards

Floor Division (//)

Divides and chops off the decimal (rounds down). 10 // 3 is 3.

7
New cards

Modulo (%)

Returns the remainder of a division. 10 % 3 is 1.

8
New cards

Type Error

Error occurring when you try to combine incompatible types (e.g., "age" + 21).

9
New cards

len()

Counts the characters (starts counting at 1)

10
New cards

len(“CS1315”)

Results in 6. It counts how many characters are in the string.

11
New cards

Index 0

The index of the first character in a Python string.

12
New cards

Index -1

The index of the last character in a Python string.

13
New cards

Slicing Syntax

string[start : stop : step]. Remember: stop is exclusive (not included).

14
New cards

“Python”[0:2]

Results in "Py". (Indices 0 and 1; 2 is excluded).

15
New cards

“Python”[::-1]

Results in "nohtyP". This is the standard trick to reverse a string.

16
New cards

.upper() / .lower()

String methods that return a copy of the string in all caps or all lowercase.

17
New cards

Assignment (=)

Used to set a variable to a value (e.g., x = 5).

18
New cards

Equality (==)

Used to compare if two things are equal (returns True or False).

19
New cards

Logical “and”

Evaluates to True only if both sides are true.

20
New cards

Logical “or”

Evaluates to True if at least one side is true.

21
New cards

“in” Operator

Checks if a substring exists within another string (e.g., 'a' in 'apple' is True).

22
New cards

“elif”

Short for "else if." It only checks this condition if the previous if was False.

23
New cards

The “Else” Rule

An else only runs if every if and elif above it was False. If one of them was True, Python skips the rest of the block.

24
New cards

While Loop Recipe

1. Initialize counter, 2. Check condition, 3. Update counter.

25
New cards

Infinite Loop

A loop that never ends because the condition never becomes False. (Usually missing i += 1).

26
New cards

Iteration

One complete execution of the block of code inside a loop.

27
New cards

Accumulator Pattern

Starting a variable at 0 or "" and adding to it inside a loop to build a final result.

28
New cards

Sentinel Condition

The condition that, once met, causes the loop to stop (e.g., while i < len(word):).

29
New cards

Casting (Conversions)

  • * int(“10“) turns a string into the number 10.

    • str(10) turns the number into the string “10”.

      • Trap: int(15.9) becomes 15. It doesn’t round; it just cuts the decimal off.