Question

python programming Question #4: # Years ago the Romans used a different system to represent numbers....

python programming

Question #4: # Years ago the Romans used a different system to represent numbers. # Instead of using the digits (0, 1, 2, 3, 4, 5, 6, etc.), the Romans # formed numbers by joining combinations of the characters # (I, V, X, L, C, D, and M). # Roman Numeral characters and their integer values are: # I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, and M = 1000. # Examples of simple Roman Numerals are: # VIII (5+1+1+1 = 8), XV (10+5 = 15), LXVI (50+10+5+1 = 66), # CLXXV (100+50+10+10+5 = 175), MXV (1000+10+5 = 1015), # where the integer amounts are arrived at by simply adding the # individual numeral values one after the other. # However, the Romans decided not to use the same 4 consecutive numerals # when forming numbers, and instead formed values such as 4, 9, 14, 19, # etc., using subtraction as follows: # IV (5-1 = 4), IX (10-1 = 9), XIV (10+5-1 = 14), # where a smaller numeral is placed to the left of the larger numeral, # and the smaller numerals value is subtracted from the larger numerals # value. # As well, only the numerals I, X, and C are used for subtraction, # and then, only in the following cases: # I can only be subtracted from V or X, # X can only be subtracted from L or C, and # C can only be subtracted from D or M. # Additionally, at most a single (1) numeral can be subtracted # from another numeral. # So, with the symbols and rules above, write the code for a Python # function that accepts an integer number from 1 to 3999 and displays # the value as a Roman Numeral (using the following dictionary): # keys: I, V, X, L, C, D, M # values: 1, 5, 10, 50, 100, 500, 1000 # For example: # Enter a value from 1 to 3999: 1929 # 1929 = MCMXXIX # index 0 1 2 3 4 5 6 # _ _ _ _ _ _ _ # |M|C|M|X|X|I|X| # | |_| | | |_| # 1000__| | | | |____9 1000 + 900 + 10 + 10 + 9 = 1929 # | | |10 # 900______| | # |_10 # HINT: The only situations in which you will need to consider subtraction # is when the ones, tens, or hundreds columns are either 4 or 9. # Start by iterating through the Roman numeral from left to right. # Copy the integer value to a temporary variable and using a while loop # continue traversing as long as the variable is > than 0. # Begin by determining if the number / 1000 results in a value >= 1, and # if so, given that the first digit can only be a 1, 2, or 3, the Roman # numeral will begin with either an "M", "MM", or "MMM" (added to a string). # After determining the the first digit's value, subtract that amount # (either 1000, 2000, or 3000) from the number. # Then, determine the value of the hundred's digit by dividing by 100. # If the digit is a 9, 5, or 4, then the hundreds portion will result in a # Roman numeral of "CM", "D", or "CD" (added to the string), and requiring # subtraction of either 900, 500, or 400 from the number. If the hundred's # digit is any other value, simply add a "C" to the string and subtract 100 # each time through the loop. # # Continue this process for the 10's and 1's columnns using the appropriate # symbols for those digits! # NOTE: This solution may require many if : / elif : / else : statements! # # Sample main program num = int(input("Enter a value from 1 to 3999: ")) for i in range(1, num + 1) : intToRoman(i) input( ) # pause the output until ENTER key is pressed

Homework Answers

Answer #1

def intToRoman(num):

value=[1,4,5,9,10,40,50,90,100,400,500,900,1000]

represent=['I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M']

roman_number="

iterator=0

while num>0:

for _ in range(num//value[i]):

roman_number+=represent[i]

num-=value[i]

iterator+=1

return roman_number

num=int(input("Enter a value from 1 to 3999: "))

for i in range(1,num+1):

res=intToRoman(i)

print(res)

sign=input().lower()

if sign=='enter':

break

here is the code to covert integer value to roman number we used two list for those values which are mostly used and referred them to make the remaining numbers. This is the easy procedure to solve this question

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The decimal values of the Roman numerals are: M D C L X V I 1000...
The decimal values of the Roman numerals are: M D C L X V I 1000 500 100 50 10 5 1 Remember, a larger numeral preceding a smaller numeral means addition, so LX is 60. A smaller numeral preceding a larger numeral means subtraction, so XL is 40. Assignment: Begin by creating a new project in the IDE of your choice. Your project should contain the following: Write a class romanType. An object of romanType should have the following...
Write an aggregate called selectivesum that sums the values of numbers in a column, but only...
Write an aggregate called selectivesum that sums the values of numbers in a column, but only if the value is present in the table t . E.g., suppose t contains the values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Suppose that table m has a column y of type integer. Here is the table M Psuedocode for the sfunc function:The result of the query SELECT selectivesum(y) FROM m; is 7. step(x, y) if(y is in t) return...
I need to change an integer and put it into an array but in a way...
I need to change an integer and put it into an array but in a way that it is read correctly. Arrays are typically drawn to be read left to right with the 0 element on the left and the largest on the right. However, arrays are a completely made up concept and are not physical in nature. So you can draw them and think about them anyway you want. For this problem having the right side as the 0...
One way to represent a very large integer (one that won't fit into a variable of...
One way to represent a very large integer (one that won't fit into a variable of type short, int, or even long) is to use an array. The array is of type int, so each element in the array can hold an integer -- we will store just one digit of our number per array element. So if a user entered 2375, it might be stored as -------------------------- | 2 | 3 | 7 | 5 | ... | --------------------------...
DISCUSS QUESTION #4 The Oxford Equipment Company purchased a machine 5 years ago at a cost...
DISCUSS QUESTION #4 The Oxford Equipment Company purchased a machine 5 years ago at a cost of $85,000. The machines expected life is 10 years and is being depreciated by the straight-line method at a rate of $8,500 per year. If the machine is kept, it can be sold for $15,000 at the end of its expected life. A new machine can be purchased for $170,000. It has an expected life of 5 years and will reduce cash operating expenses...
Lab 2 Write a C program that runs on ocelot for a mini calculator using only...
Lab 2 Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the command line. The calculator will only do addition, subtraction, multiplication, division, and a power of 2. Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-x] value • The variable value is the starting value. • Value should be validated to be an integer between 1 and 50 inclusive. Error message and...
Could I get some assistance on the following question please. The undercarriage of an aircraft is...
Could I get some assistance on the following question please. The undercarriage of an aircraft is comprised of TWO sprung wheel assemblies EACH with 4 springs. The springs are designed to (i) support the weight of the aircraft when stationary on the ground and (ii) absorb the vertical kinetic energy of the aircraft when it touches down. The mass of the aircraft is 10000 kg. All springs have an identical spring constant of k = 100 kN/m. Ignore effects such...
Question 1 Suppose that the scores of the semester exam has a normal distribution with mean...
Question 1 Suppose that the scores of the semester exam has a normal distribution with mean of 120 and standard deviation of 17. If the bottom 30% of the students failed in the exam. (1). What was the passing score? Question 2 A 100-watt light bulb has an average brightness of 1640 lumens, with a standard deviation of 62 lumens. Suppose that the brightness of bulbs follows normal distribution, then (2). In a lot of 10000 such bulbs, what would...
Question 3 (25%) Write your code in Q3( ) that prompts user to input the value...
Question 3 (25%) Write your code in Q3( ) that prompts user to input the value of n (integer). Then you program displays a list of n common multiples of the 4 th and 5 th digits of your student ID number, starting from the least common multiples first. If the digit is 0, use 10 for that digit. Then the program further calculates and displays the average of those n numbers. Sample display 1 (let ID = 19204618A) Input...
4. (1 point) Consider the following pmf: x = -2 0 3 5 P(X = x)...
4. (1 point) Consider the following pmf: x = -2 0 3 5 P(X = x) 0.34 0.07 ? 0.21 What is the E[ X 1 + X ] 5. (1 point) Screws produced by IKEA will be defective with probability 0.01 independently of each other. What is the expected number of screws to be defective in any given pack? Hint: you should be able to recognize this distribution and use the result from the Exercises at the end of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT