Check if an input is a valid roman numeral

后端 未结 5 656
醉话见心
醉话见心 2021-01-14 10:46

I got a program that converts Roman numerals to integers and vice versa. My problem is that I don´t really know how to create a function that checks if the user input is a v

5条回答
  •  天命终不由人
    2021-01-14 11:03

    Apart from the design problems that have already been pointed out, I'd like to just answer the question why your for-loop doesn't go through all the numerals

    If the entries are considered valid by your code, then the loop goes into the elif clause where it calls romanToInt(numeral)and then break. There's your problem: break take that out.

    Illustration: As soon as condition is met in this example, the loop will stop going through i in list

    for i in list:
       # do something
       if condition:
           break # "Stop the innermost loop now!"
    

提交回复
热议问题