1. Home
  2. Explore
  3. Computer Science
  4. Modular Arithmetic in Python

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Modular Arithmetic in Python

  • 51Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Modulo Fundamentals
Modular arithmetic uses an operation that returns the
left after division.

51 questions

  1. 1
    Modular arithmetic uses an operation that returns the
    _____
    left after division.
    Hint

    Think about what remains when you subtract the divisor's full groups from the dividend.

    Answer

    remainder

    Explanation

    The modulo operation returns the remainder after division.

  2. 2
    In the expression aaa modulo bbb, the number bbb is the
    _____
    .
    Hint

    This value determines the range of outputs for the operation.

    Answer

    modulus

    Explanation

    The content identifies bbb as the modulus, which sets the range of outputs.

  3. 3
    In the division setup described, the number being divided, represented by aaa, is the
    _____
    .
    Hint

    It is the number that gets divided by another number.

    Answer

    dividend

    Explanation

    The dividend is the number being divided.

  4. 4
    In the division setup described, the number that divides the dividend, represented by bbb, is the
    _____
    .
    Hint

    It is the number that goes into the dividend.

    Answer

    divisor

    Explanation

    The divisor is the number by which the dividend is divided.

  5. 5
    The quotient qqq represents the number of times the
    _____
    goes into the dividend.
    Hint

    It is the number used to divide the dividend.

    Answer

    divisor

    Explanation

    The quotient counts how many times the divisor can go into the dividend.

  6. 6
    The quotient and remainder together describe division through the relationship a=bq+ra = bq + ra=bq+r, where rrr is the
    _____
    .
    Hint

    It represents the leftover part after counting full groups.

    Answer

    remainder

    Explanation

    In this relationship, the dividend equals the divisor times the quotient plus the remainder.

  7. 7
    If the divisor goes evenly into the dividend, the
    _____
    is zero.
    Hint

    There is nothing left over after forming complete groups.

    Answer

    remainder

    Explanation

    Exact division leaves no leftover amount, so the remainder is zero.

  8. 8
    For a positive modulus, the modulus helps set the
    _____
    of possible modulo outputs.
    Hint

    It describes the set of values that the results can occupy.

    Answer

    range

    Explanation

    The modulus sets the range of outputs for the modulo operation.

  9. 9
    In Python, the built-in modulo expression is written using the
    _____
    symbol.
    Hint

    It is also called the percent symbol.

    Answer

    percentage sign

    Explanation

    Python uses the percentage sign, written as %, for its built-in modulo expression.

  10. 10
    Python's built-in modulo expression works with integers and
    _____
    numbers.
    Hint

    These numbers can include a fractional part.

    Answer

    floating

    Explanation

    The modulo expression works on both integers and floating numbers.

  11. 11
    The examples in the lesson focus on
    _____
    to keep the calculations simple.
    Hint

    These are whole numbers, including negative whole numbers.

    Answer

    integers

    Explanation

    Although Python's modulo expression also works with floating numbers, the lesson focuses on integers for simplicity.

  12. 12
    Besides the built-in % expression, Python can use functions such as
    _____
    to conduct modulo operations.
    Hint

    This function name begins with the letter f.

    Answer

    fmod

    Explanation

    The lesson mentions fmod as another function that can conduct modulo operations.

  13. 13
    When 666 is divided by 222, the modulo result is
    _____
    .
    Hint

    The divisor fits an exact number of times, with nothing left over.

    Answer

    0

    Explanation

    Since 222 goes into 666 three times exactly, the remainder is 000.

  14. 14
    In the calculation 666 modulo 222, the quotient is
    _____
    .
    Hint

    Count how many groups of two fit into six.

    Answer

    3

    Explanation

    The divisor 222 goes into the dividend 666 three times.

  15. 15
    When 555 is divided by 222, the modulo result is
    _____
    .
    Hint

    After removing two complete groups of two, consider what is left.

    Answer

    1

    Explanation

    Two groups of 222 make 444, leaving a remainder of 111 from 555.

  16. 16
    In the calculation 555 modulo 222, the quotient is
    _____
    .
    Hint

    Count the complete groups of two that fit into five.

    Answer

    2

    Explanation

    The divisor 222 fits into 555 twice, with 111 left over.

  17. 17
    Floor division returns the
    _____
    rather than the remainder.
    Hint

    It tells how many whole groups of the divisor fit into the dividend.

    Answer

    quotient

    Explanation

    Floor division returns the quotient, not the leftover amount.

  18. 18
    For positive integers, floor division gives the
    _____
    number of times the divisor goes into the dividend.
    Hint

    It excludes any fractional part of the division result.

    Answer

    whole

    Explanation

    The lesson describes floor division as returning the whole-number quotient.

  19. 19
    For 555 floor-divided by 222, the quotient used in the remainder calculation is
    _____
    .
    Hint

    It is the number of complete groups of two in five.

    Answer

    2

    Explanation

    Floor division gives a quotient of 222 for 555 divided by 222.

  20. 20
    For 555 modulo 222, multiplying the floor-division quotient by the modulus gives
    _____
    .
    Hint

    Use the quotient 222 and multiply it by the modulus 222.

    Answer

    4

    Explanation

    The quotient is 222, and 222 multiplied by the modulus 222 gives 444.

  21. 21
    To calculate the remainder from the dividend and the product of the quotient and modulus, subtract that product from the
    _____
    .
    Hint

    This is the original number being divided.

    Answer

    dividend

    Explanation

    For 555 modulo 222, subtract 444 from the dividend 555 to obtain the remainder 111.

  22. 22
    A from-scratch modulo function can calculate the remainder as a−(a//b)×ba - (a // b) \times ba−(a//b)×b, using floor division to find the
    _____
    .
    Hint

    This value counts the complete groups that fit into the dividend.

    Answer

    quotient

    Explanation

    The expression first uses floor division to find the quotient, multiplies it by the modulus, and subtracts that product from the dividend.

  23. 23
    In the from-scratch function, the name mod is used for the
    _____
    in the modulo operation.
    Hint

    It is the value that the dividend is divided by.

    Answer

    modulus

    Explanation

    The function's mod input represents the modulus used to calculate the remainder.

  24. 24
    The lesson tests the custom modulo function using integers from negative 101010 up to, but not including,
    _____
    .
    Hint

    The upper endpoint of this range is excluded.

    Answer

    10

    Explanation

    The tested range starts at negative 101010 and ends before 101010, so its largest included integer is 999.

  25. 25
    The custom function is checked by comparing its results with Python's built-in
    _____
    operation.
    Hint

    This is the operation represented by the % symbol.

    Answer

    modulo

    Explanation

    The test checks whether the custom function agrees with Python's built-in modulo operation.

  26. 26
    In military time, the hour cycles from 000000000000 through
    _____
    before wrapping around.
    Hint

    This is the final hour shown before midnight.

    Answer

    2300

    Explanation

    The military-time clock runs from 000000000000 to 230023002300 and then wraps to 000000000000.

  27. 27
    The modulus used to wrap the clock's hour back to the start of a day is
    _____
    .
    Hint

    It is the number of hours in a full day.

    Answer

    24

    Explanation

    The clock uses modulo 242424 so that hours wrap around after a full day.

  28. 28
    When an hour calculation reaches 242424, the clock wraps to hour
    _____
    rather than showing 240024002400.
    Hint

    This is the first hour in the clock's cycle.

    Answer

    0

    Explanation

    Applying modulo 242424 to 242424 produces 000, so the clock starts again at hour zero.

  29. 29
    To project a clock time forward or backward, the function adds the hour offset to the current hour and applies modulo
    _____
    .
    Hint

    Use the clock's full-cycle length as the modulus.

    Answer

    24

    Explanation

    The updated hour is calculated by adding the offset to the current hour and taking the result modulo 242424.

  30. 30
    A positive hour offset can project the clock to a
    _____
    time.
    Hint

    It moves forward from the current hour.

    Answer

    future

    Explanation

    Adding a positive number of hours projects the clock forward in time.

  31. 31
    A negative hour offset can be used to calculate a
    _____
    time.
    Hint

    It moves backward from the current hour.

    Answer

    previous

    Explanation

    Using a negative offset allows the function to calculate an earlier time.

  32. 32
    If the current time is 232023202320 and the clock advances one hour, the wrapped military time is
    _____
    .
    Hint

    The hour wraps to zero, while the minutes remain unchanged.

    Answer

    0020

    Explanation

    Adding one to hour 232323 wraps the hour to 000 under modulo 242424, and the minutes stay at 202020.

  33. 33
    The clock function's default hour offset is
    _____
    .
    Hint

    With this setting, no hours are added or subtracted.

    Answer

    0

    Explanation

    A default offset of 000 makes the function display the current hour.

  34. 34
    The clock function changes the hour while leaving the current
    _____
    unchanged.
    Hint

    This is the smaller time unit that the function does not increment.

    Answer

    minutes

    Explanation

    The function adjusts the hour offset but does not change the minutes.

  35. 35
    The clock function described in the lesson displays its result using
    _____
    rather than returning a value for further use.
    Hint

    This action writes output to the screen.

    Answer

    print

    Explanation

    The lesson's clock function prints the formatted time and does not return a value.

  36. 36
    The clock obtains the current date and time using Python's
    _____
    functionality.
    Hint

    Its name combines the words for a date and a time.

    Answer

    datetime

    Explanation

    The function uses datetime to obtain the current date and time.

  37. 37
    The clock uses the Python package
    _____
    to specify a time zone.
    Hint

    The package name begins with the letters p and y.

    Answer

    pytz

    Explanation

    The function uses pytz to select the time zone for the requested clock time.

  38. 38
    The clock function's default time zone in the lesson is
    _____
    .
    Hint

    It is the time zone used by default in the example.

    Answer

    eastern standard time

    Explanation

    The function sets eastern standard time as its default time zone.

  39. 39
    Without a specified time zone, the time retrieval described in the lesson returns
    _____
    time.
    Hint

    This is a globally standardized time reference.

    Answer

    universal

    Explanation

    The lesson says that without a specified time zone, the time would be returned as universal time.

  40. 40
    To get the current time for Addis Ababa, the function's time-zone setting should be
    _____
    .
    Hint

    Use the location named in the example as the selected time zone.

    Answer

    Addis Ababa

    Explanation

    Setting the time zone to Addis Ababa lets the function display the current time there.

  41. 41
    The time-zone listing function mentioned in the lesson returns a
    _____
    of available time zones.
    Hint

    It is an ordered collection of entries.

    Answer

    list

    Explanation

    The all time zones function is described as returning a list of time zones.

  42. 42
    When the minute value has only one digit, a leading
    _____
    is added for military-time formatting.
    Hint

    This keeps the minute field two digits long.

    Answer

    0

    Explanation

    A leading zero is added to minutes below 101010, such as formatting 999 as 090909.

  43. 43
    When the updated hour has only one digit, a leading
    _____
    is added to the hour string.
    Hint

    The clock uses two digits for its hour field.

    Answer

    0

    Explanation

    A leading zero ensures that hours from 000 through 999 are displayed with two digits.

  44. 44
    The clock converts the hour and minute values to
    _____
    before formatting them for display.
    Hint

    These are text representations of the numeric values.

    Answer

    strings

    Explanation

    The function converts the numbers to strings so it can add leading zeros and display them together.

  45. 45
    In the Diffie-Hellman key exchange, modular arithmetic helps two parties securely exchange cryptographic
    _____
    over a public channel.
    Hint

    These are the items used by cryptographic systems to protect information.

    Answer

    keys

    Explanation

    Diffie-Hellman allows two parties to securely exchange cryptographic keys over a public channel.

  46. 46
    The Diffie-Hellman key exchange is an application of modular arithmetic in
    _____
    .
    Hint

    This field focuses on securing information and communications.

    Answer

    cryptography

    Explanation

    The lesson identifies Diffie-Hellman as a cryptographic application of modular arithmetic.

  47. 47
    A UPC or barcode helps grocery stores track
    _____
    in a store.
    Hint

    These are the products being sold, such as cereal boxes and soup cans.

    Answer

    items

    Explanation

    UPC codes and barcodes help stores track the items they carry.

  48. 48
    The UPC described in the lesson is made up of
    _____
    digits.
    Hint

    This is the number of digits stated for the code in the lesson.

    Answer

    10

    Explanation

    The lesson describes a UPC as comprising 101010 digits used to track an item.

  49. 49
    A UPC uses a
    _____
    based on modular arithmetic to help verify that the code is valid.
    Hint

    It is a calculated value used to detect errors in a code.

    Answer

    checksum

    Explanation

    The UPC checksum uses modular arithmetic to help verify the validity of the code.

  50. 50
    The international standard book number, or ISBN, is used to verify
    _____
    .
    Hint

    It identifies the kind of publication the number is associated with.

    Answer

    books

    Explanation

    The lesson describes the ISBN as a system used to verify books.

  51. 51
    The ISBN example uses modular arithmetic to create
    _____
    values for books.
    Hint

    Each value distinguishes the book from others.

    Answer

    unique

    Explanation

    The lesson notes that unique ISBN values are made using modular arithmetic.

1 of 51
Question 1 of 51

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent