1. Homepage
  2. Programming
  3. COMP9021 Principles of Programming Term 1 - Assignment 1: Convert Roman numeral to Arabic

COMP9021 Principles of Programming Term 1 - Assignment 1: Convert Roman numeral to Arabic

Engage in a Conversation
UNSWCOMP9021Principles of ProgrammingPython

COMP9021 Principles of Programming Term 1, 2024 CourseNana.COM

Assignment 1
Worth 13marks and due Week 7 Monday @ 10am CourseNana.COM

1. General Matters 1.1 Aim CourseNana.COM

The purpose of this assignment is to: CourseNana.COM

  • develop your problem-solving skills. CourseNana.COM

  • design and implement the solution to a problem in the form of a medium sized Python program. CourseNana.COM

  • practice the use of arithmetic computations, tests, repetitions, lists, and strings. CourseNana.COM

  • use procedural programming. CourseNana.COM

    1.2 Marking
    This assignment is worth 13 marks distributed approximately as follows: CourseNana.COM

    1.50 marks for "I don't get what you want, sorry mate!"
    3.50 marks for "Hey, ask me something that's not impossible to do!" 2.25 marks for "Please convert ***"
    2.50 marks for "Please convert *** using ***"
    3.25 marks for "Please convert *** minimally" CourseNana.COM

    ---------------------------------------------------------------------- 13.00 marks total CourseNana.COM

    Your program will be tested against several inputs. For each test, the automarking script will let your program run for 30 seconds. The outputs of your program should be exactly as indicated. CourseNana.COM

1.3 Due Date and Submission CourseNana.COM

Your program will be stored in a file named roman_arabic.py. The assignment can be submitted more than once. The last version just before the due date and time will be marked (unless you submit late in which case the last late version will be marked). CourseNana.COM

Assignment 1 is due Week 7 Monday 25 March 2024 @ 10:00am (Sydney time)
Note that
late submission with 5% penalty per day is allowed up to 5 days from the due date, that is, any CourseNana.COM

late submission after Week 7 Saturday 30 March 2024 @ 10:00am will be discarded. CourseNana.COM

Make sure not to change the filename roman_arabic.py while submitting by clicking on [Mark] button in Ed. It is your responsibility to check that your submission did go through properly using Submissions link in Ed otherwise your mark will be zero for Assignment 1. CourseNana.COM

1.4 Reminder on Plagiarism Policy CourseNana.COM

You are permitted, indeed encouraged, to discuss ways to solve the assignment with other people. Such discussions must be in terms of algorithms, not code. But you must implement the solution on your own. Submissions are scanned for similarities that occur when students copy and modify other people’s work or work very closely together on a single implementation. Severe penalties apply. CourseNana.COM

2. Description
You will design and implement a program that prompts the user for an input with: CourseNana.COM

How can I help you? CourseNana.COM

User input should be one of three possible kinds:
Please convert *** CourseNana.COM

Please convert *** using *** Please convert *** minimally CourseNana.COM

If the user input is not of this form, with any occurrence of***an arbitrary nonempty sequence of non-space symbols, then the program should print out: CourseNana.COM

and stop. CourseNana.COM

I don't get what you want, sorry mate! CourseNana.COM

2.1 First Kind of Input CourseNana.COM

In case the user inputs Please convert ***, then *** should be either a strictly positive integer (whose representation should not start with 0) that can be converted to a Roman number CourseNana.COM

(hence be at most equal to 3999), or a valid Roman number; otherwise, the program should print out: CourseNana.COM

Hey, ask me something that's not impossible to do! CourseNana.COM

and stop.
If the input is as expected, then the program should perform the conversion, from
Arabic to CourseNana.COM

Roman or from Roman to Arabic, and print out the result in the form: Sure! It is *** CourseNana.COM

2.2 Second Kind of Input CourseNana.COM

In case the user inputs Please convert *** using ***, then the first *** should be a strictly positive integer (whose representation should not start with 0) or a sequence of (lowercase or uppercase) letters and the second *** should be a sequence of distinct (lowercase or uppercase) letters. CourseNana.COM

Moreover: CourseNana.COM

  • the second *** is intended to represent a sequence of so-called generalised Roman symbols. The classical Roman symbols corresponding to the sequence MDCLXVI, whose rightmost element is meant to represent 1, the second rightmost element 5, the third rightmost element 10, etc. CourseNana.COM

  • if it is not an integer, the first *** is intended to represent a so-called generalised Roman number, that is, a sequence of generalised Roman symbols that can be decoded using the provided sequence of generalised Roman symbols similarly to the way Roman numbers are represented. CourseNana.COM

    If that is not the case, or if it is not possible to convert the first *** from Arabic to generalised Roman or from generalised Roman to Arabic, then the program should print out: CourseNana.COM

    Hey, ask me something that's not impossible to do! CourseNana.COM

    and stop. CourseNana.COM

If the input is as expected and the conversion can be performed, then the program should indeed perform the conversion, from Arabic to generalised Roman or from generalised Roman to Arabic, and print out the result in the form: CourseNana.COM

Sure! It is *** CourseNana.COM

2.3 Third Kind of Input CourseNana.COM

In case the user inputs Please convert *** minimally, then *** should be a sequence of (lowercase or uppercase) letters. The program will try and view *** as a generalised Roman number with respect to some sequence of generalised Roman symbols. If that is not possible, then the program should print out: CourseNana.COM

Hey, ask me something that's not impossible to do! CourseNana.COM

and stop.
Otherwise, the program should find the smallest integer that could be converted from
***, CourseNana.COM

viewed as some generalised Roman number, to Arabic, and output a message of the form Sure! It is *** using *** CourseNana.COM

3. Sample Outputs (or Test Cases) CourseNana.COM

Here are a few tests together with the expected outputs. The outputs of your program should be exactly as shown: CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please do my assignment... I don't get what you want, sorry mate! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? please convert 35 I don't get what you want, sorry mate! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 035
Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 4000
Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert IIII
Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert IXI
Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 35 Sure! It is XXXV CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 1982 Sure! It is MCMLXXXII CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 3007 Sure! It is MMMVII CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert MCMLXXXII Sure! It is 1982 CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert MMMVII Sure! It is 3007 CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 123 by using ABC I don't get what you want, sorry mate! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 123 ussing ABC I don't get what you want, sorry mate! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert XXXVI using VI Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert XXXVI using IVX Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert XXXVI using XWVI Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert I using II Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert _ using _
Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert XXXVI using XVI Sure! It is 36 CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert XXXVI using XABVI Sure! It is 306 CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert EeDEBBBaA using fFeEdDcCbBaA Sure! It is 49036 CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 49036 using fFeEdDcCbBaA Sure! It is EeDEBBBaA CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 899999999999 using CourseNana.COM

AaBbCcDdEeFfGgHhIiJjKkLl CourseNana.COM

Sure! It is Aaaabacbdcedfegfhgihjikjlk CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCDEFGHIJKLMNOPQRST using CourseNana.COM

AbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStT CourseNana.COM

Sure! It is 11111111111111111111 CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 1900604 using LAQMPVXYZIRSGN Sure! It is AMAZING CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCD minimally using ABCDE I don't get what you want, sorry mate! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCD minimaly I don't get what you want, sorry mate! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert 0I minimally Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABAA minimally Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCDEFA minimally Hey, ask me something that's not impossible to do! CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert MDCCLXXXVII minimally Sure! It is 1787 using MDCLXVI CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert MDCCLXXXIX minimally Sure! It is 1789 using MDCLX_I CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert MMMVII minimally Sure! It is 37 using MVI CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert VI minimally Sure! It is 4 using IV CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCADDEFGF minimally Sure! It is 49269 using BA_C_DEF_G CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCCDED minimally CourseNana.COM

Sure! It is 1719 using ABC_D_E CourseNana.COM

4. Hints CourseNana.COM

4.1 Explaining the following example of the third kind of input (Please convert *** minimally): CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert ABCADDEFGF minimally Sure! It is 49269 using BA_C_DEF_G CourseNana.COM

First, remember the two important Roman numeral rules below: CourseNana.COM

1. A Roman symbol is repeated three times but not more than that. However, the symbols V (5), L (50) and D (500) are never repeated. CourseNana.COM

2. The Roman symbols V (5), L (50) and D (500) are never written to the left of a symbol of greater value, i.e., V (5), L (50) and D (500) are never subtracted. The symbol I (1) can be subtracted from V (5) and X (10) only. The symbol X can be subtracted from L (50) and C (100) only. CourseNana.COM

Note also that "minimally" means we are looking for a generalised Roman symbols that can convert the given numeral into a smallest integer number. CourseNana.COM

Let us start assigning Roman numeral values from the right-hand side such that the value is minimum. CourseNana.COM

Starting with F, we can see it is repeated and we have to assign the minimum value to FGF in order to assign the minimum value to F. From a number of various combinations, we know that the only possible solution here is F=10 and G=1 (try out combinations of 1, 5, 10 here to see why this is the right one). Thus FGF=19. CourseNana.COM

Let us move now to the next element, which is E. We also need to consider the element after E in order to assign a smaller combination, if possible, in this case. The next element is D, which is repeated and therefore cannot be less than E. Thus, we assign E the smallest number not used yet, which is 50. Moving on to D, since it is repeated, it cannot be greater than the next element A. Thus, we assign the smallest number not yet used which is 100 to D. CourseNana.COM

Till now, our number DDEFGF is resulting in 269 using DEF_G (value 5 not assigned). CourseNana.COM

The next element is A and it is repeated. To assign a value to A, we must assign a value so that ABCA does not violate Roman numeral rules. That is, A < B and B > C. Because of AB (A and B being next to each other), we cannot assign A as 500 (500 cannot be subtracted from any number). CourseNana.COM

Let us say we assign 1000 to A. Then B can be either 5000 or 10000. B cannot be 5000 because that would mean C can only be 500. Also, B cannot be 10000 as it would mean C should be 5000 or 500 (both are invalid assignments). CourseNana.COM

Let us try to assign 10000 to A (it cannot be assigned 5000 since it is repeated). B can be either 50000 or 100000. If B is 50000, C can be either 5000, 1000 or 500. C cannot be 5000 or 500 (since they be subtracted from any number). C can be 1000. CourseNana.COM

Consequently, the smallest we can come up with here is 10000 for A, 50000 for B, and 1000 for C, and ABCA = 50000 - 10000 + 10000 - 1000 = 49000. CourseNana.COM

Thus, the total becomes 49269 using BA_C_DEF_G (values 5, 500 and 5000 not assigned). CourseNana.COM

4.2 More examples about the third kind of input (Please convert *** minimally): CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert AZERTY minimally Sure! It is 444 using ZAREYT CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert XXXVVVIII minimally Sure! It is 333 using X_V_I CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert AhZhJ minimally Sure! It is 691 using Ah_Z_J CourseNana.COM

$ python3 roman_arabic.py
How can I help you? Please convert BCBC minimally Hey, ask me something that's not impossible to do! CourseNana.COM

CourseNana.COM

5. Useful Links CourseNana.COM

  1. 1)  Convert Roman Numerals to Arabic CourseNana.COM

    https://www.calculateme.com/roman-numerals/from-roman CourseNana.COM

  2. 2)  Convert Arabic to Roman Numerals CourseNana.COM

    https://www.calculateme.com/roman-numerals/to-roman CourseNana.COM

  3. 3)  Converting Roman Numerals to Arabic Numbers CourseNana.COM

    https://www.periodni.com/roman_numerals_converter.html CourseNana.COM

  4. 4)  Roman Numerals Converter CourseNana.COM

    http://www.convertit.com/Go/Maps/Calculators/Math/Roman_Numerals_Converter.ASP CourseNana.COM

  5. 5)  Roman Numeral Converter CourseNana.COM

    https://www.calculatorsoup.com/calculators/conversions/roman-numeral-converter.php CourseNana.COM

  6. 6)  Roman Numerals CourseNana.COM

    http://aven.amritalearning.com/index.php?sub=99&brch=292&sim=1438&cnt=3231 CourseNana.COM

  7. 7)  Roman numerals CourseNana.COM

    https://en.wikipedia.org/wiki/Roman_numerals CourseNana.COM

  8. 8)  Roman Numerals CourseNana.COM

    https://roman-numerals.info/ CourseNana.COM

  9. 9)  HowtoConvertRomanNumerals:3EasyMethods https://blog.prepscholar.com/roman-numerals-converter CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
UNSW代写,COMP9021代写,Principles of Programming代写,Python代写,UNSW代编,COMP9021代编,Principles of Programming代编,Python代编,UNSW代考,COMP9021代考,Principles of Programming代考,Python代考,UNSWhelp,COMP9021help,Principles of Programminghelp,Pythonhelp,UNSW作业代写,COMP9021作业代写,Principles of Programming作业代写,Python作业代写,UNSW编程代写,COMP9021编程代写,Principles of Programming编程代写,Python编程代写,UNSWprogramming help,COMP9021programming help,Principles of Programmingprogramming help,Pythonprogramming help,UNSWassignment help,COMP9021assignment help,Principles of Programmingassignment help,Pythonassignment help,UNSWsolution,COMP9021solution,Principles of Programmingsolution,Pythonsolution,