Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The ancient Babylonians represented numbers by writing their digits, in order, a

ID: 3751367 • Letter: T

Question

The ancient Babylonians represented numbers by writing their digits, in order, as sequences of cuneiform symbols (pressed
into clay tablets with a stylus). They used a base-60 number system, so a single “digit” could range in value from 0 through
59; compare this to the base-10 Indo-Arabic number system that we use, where a single digit can only represent a value in
the range 0–9. We can’t easily reproduce these cuneiform symbols in text, so we will have to improvise:

< represents the quantity 10
T represents the quantity 1
n represents the quantity 0 (technically, the Babylonians didn’t have the concept of “zero”, but they used this symbol,
by itself, as a placeholder between the other digits in a number, as in 101)

A single digit is represented by a sequence of one or more of the symbols above. To calculate the digit’s value, add up
the values associated with each symbol in the sequence (you may find Python’s count() string method useful here). For
example, “< <T” represents the quantity 21 (two 10’s, plus 1). Within a sequence, all of the ‘<’ symbols (if there are any)
will come before any ‘T’ symbols, so you’ll never see something like “<TT<”. Simimlarly, a single sequence will never
contain more than five ‘<’ symbols, or more than nine ‘T’ symbols.
NOTE: The backslash character has special meaning within a Python string. To represent a (single) backslash character in a
string (for example, to test for equality), use a double-backslash, as in “nn”.
Complete the babylonian() function, which takes one argument: a list of strings, each of which contains a sequence of
the pseudo-cuneiform symbols listed above. This function translates each string into the corresponding Indo-Arabic number
(a value between 0 and 59, inclusive) and returns a new list containing those integers in the same order as they appear in the
original list. For example, the input [“<TT”, “n”, “< <”] would produce the translated list [12, 0, 20].

Optional Problem Extension:
The program above translates a Babylonian number into digits, but it does not compute the final number. Each column in a
Babylonian number is equal to the digit in that column, multiplied by a power of 60. The last (far right) column is the “ones”
column; its digit value is multiplied by 600 or 1. As we move to the left, each column increments the previous power of 60
by 1 (i.e., the digit in the next-to-last column is multiplied by 601 or 60, the column immediately to its left is multiplied by
602 or 3600, and so on). The final number equals the sum of these products. For example, the 4-digit sequence [22, 0, 5, 48]
represents the numerical quantity
22603+0602+5601+48600 = 22216; 000+03; 600+560+481 = 4; 752; 000+0+300+48 = 4; 752; 348
Modify your function so that, after translating the list of digits, it returns the combined final numerical value (instead of the
list of digits). The process is (roughly) as follows:

1. Create variables to hold the final answer (initialized to 0) and the current exponent (if your loop runs from index 0
through the end, initialize this value to 1 less than the number of digits)
2. For each digit in your list, multiply it by 60 raised to the current exponent value. Add the product to your running
total, then decrement the value of the exponent by 1

This modification is worth 2 points per correct answer, rather than 1.

Function Call Return Value (1 point) Return Value (2 points) babylonian(["TTT", "<"]) [3, 10] 190 babylonian(["<T", "nn", "TTTTTT"]) [11, 0, 6] 39606 babylonian(["<<<TTTTTTT", "<", "nn", "TTTT", "<<<<<"]) [37, 10, 0, 4, 50] 481680290

Explanation / Answer

def babylonian(babylonian_strings):
    indo_arabic_digits = []

    for babylonian_string in babylonian_strings:
        number_of_tens = babylonian_string.count('<')
        number_of_ones = babylonian_string.count('T')

        indo_arabic = (10*number_of_tens) + (1*number_of_ones)

        indo_arabic_digits.append(indo_arabic)

    indo_arabic_number = 0
    #calculate the actual indo-arabic number
    for exponent in range(0, len(indo_arabic_digits)):
        digit_position = -(exponent + 1)
        indo_arabic_number = indo_arabic_number + indo_arabic_digits[digit_position] * (60**exponent)

    return indo_arabic_number

print(babylonian(["TTT", "<"]))
print(babylonian(["<T", "nn", "TTTTTT"]))
print(babylonian(["<<<TTTTTTT", "<", "nn", "TTTT", "<<<<<"]))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote