Comp 1701 Python - Selections and Repetition

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

1/5

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

6 Terms

1
New cards

All the comparison operators

x != y # x is not equal to y

x > y # x is greater than y

x < y # x is less than y

x >= y # x is greater than or equal to y

x <= y # x is less than or equal to y

2
New cards

What are the Logical Operators? What two are Boolean values?

"and", "or", "not" -> All three operators take Boolean operands and produce Boolean values

Boolean values: “True” and “False” with capitalization mattering

3
New cards

Order of precedence 

Think of bedmas 

  1. Brackets () - Highest

  2. Functions 

  3. Exponents [ ** ]

  4. Multiplication/Division/Division Where you round down /Modulo [ * , /, //, % ]

  5. Addition/Subtraction [ +, - ]

  6. Relational/Operators [ ==, !=, >, <, >=, <= ]

  7. Logical “not” [ not ]

  8. Logical “and” [ and ]

  9. logical “or” [ or ] - Lowest

  10. If, else, elif

4
New cards

How to calculate modulo on calculator 

Divide the two numbers 

Subtract the whatever number to answer to get it to 0.decimal 

then multiple by the second number and round 

Example:

  1. 263 / 14 = 18.785714

  2. We only want 0.785714 so subtract this answer by 18

  3. Multiple that answer by the second number (14) → 14 x .785714 = 10.999996 or 11 rounded

5
New cards

Chained conditionals example

if x < y:
  print("x is less than y")
elif x > y:
  print("x is greater than y")
else:
  print("x and y must be equal")

While nested would be:

f x < y:
    print("x is less than y")
else:
    if x > y:
        print("x is greater than y")
    else:
        print("x and y must be equal")

So Chained so no if/else/elif within another if/else/elif. While a nested is the oppositie where there are other

6
New cards

  1. ()

  2. f(x) - functions

  3. *, /, //, % -

  4. +, -

  5. ><, <=>, =, ==, !=

(Not, and or)

  • "if"