Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python Write a function moronic2arabic() that takes a string argument consisting of properly-formatted Moronicnumerals and returns the integer represented by the Moronic numerals. The converted

python

image text in transcribed

Write a function moronic2arabic() that takes a string argument consisting of properly-formatted Moronicnumerals and returns the integer represented by the Moronic numerals. The converted integer is guaranteed to be in the range [1, 3071].

Process the input string from left-to-right, looking for combinations of numerals (doubles and triples that indicate subtraction) or single numerals that are not involved in subtraction. Add the value of the numeral combination or singleton to a running total and move on to the remainder of the input string. To find combinations of numerals, examine two or three characters simultaneously (e.g., SSF or IE), taking care not to overrun the end of the string while doing this. Proceed in this manner until the rightmost numeral has been processed.

Examples:

image text in transcribed

def moronic2arabic(numerals): return None 

if __name__ == "__main__": 
 print('Testing moronic2arabic() for "SIE": ' + str(moronic2arabic('SIE'))) print('Testing moronic2arabic() for "SSSSSEESIIII": ' + str(moronic2arabic('SSSSSEESIIII'))) print('Testing moronic2arabic() for "FSSFIIII": ' + str(moronic2arabic('FSSFIIII'))) print('Testing moronic2arabic() for "FFFIIE": ' + str(moronic2arabic('FFFIIE'))) print('Testing moronic2arabic() for "FFFSFEIE": ' + str(moronic2arabic('FFFSFEIE'))) 
You've heard of Roman numerals, but have you heard of Moronic numerals? Probably not because we've invented them for this homework assignment. Moronic numerals are similar to Roman numerals in that numbers are formed by combining symbols and adding the values In Moronic numerals, each numeral has a fixed value representing a power of 8 (rather than a power of 10 or half of a power of 10, as in Roman numerals) Symbol: I E S F Value: 1 3 64 512 Symbols are placed from left to right in order of value, starting with the largest. For example, FFFFSSSEEEEEllll s 2, 284 (512 x 4) (64 x 3) (8 x 5) (4 x 1) In a few specific cases, to avoid having six or more characters being repeated in succession (such as llllll or EEEEEE), subtractive notation is used, as in this table: Number 6 7 48 (64 2x 8) 56 (64 1x8) 384 (512 2x64) 448 (512-1x64) Notation: ILE DE EES SF ES SSF

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions