'conversion from integer to roman number [closed]
conversion of integer to roman number error:- SyntaxError: unexpected character after line continuation character ^ hundredth = s\100 Line 27 (Solution.py)
class Solution: def intToRoman(self, num: int) -> str: s = int(num)
standard_keys = (1,5,10,50,100,1000)
standard_values = ('I','V','X','L','C','D',M)
keys = (0,1,2,3,4,5,6,7,8,9)
ones_values = ('','I','II','III','IV','V','VI','VII','VIII','XI')
tens_values = ('','X','XX','XXX','XL','L','LX','LXX','LXXX','XD')
hundreds_value = ('','C','CC','CCC','CD','D','DC','DCC','DCCC','CM')
standard_dict = dict.fromkeys(standard_keys,standard_values)
ones_dict = dict.fromkeys(keys,ones_value)
tens_dict = dict.fromkeys(keys,tens_value)
hundreds_dict = dict.fromkeys(keys,hundreds_value)
if(s == 1 or s == 5 or s == 10 or s == 50 or s == 100 or s == 1000):
string = standard_dict.get(s)
return string
string = ''
if(s/100 != 0):
hundredth = s\100
string += hundreds_dict.get(hundredth)
s -= (hundredth*100)
tenth = s\10
string += tens_dict.get(tenth)
s -= (tenth*10)
ones = s
ones_dict.get(ones)
elif(s\10 != 0 ):
tenth = s\10
string += tens_dict.get(tenth)
s -= (tenth*10)
ones = s
string += ones_dict.get(ones)
else:
ones = s
string += ones_dict.get(ones)
return string
Above program is a python code to convert integer to roman number
i am getting few errors which i am not able to solve
can you resolve the below error
SyntaxError: unexpected character after line continuation character ^ hundredth = s\100 Line 27 (Solution.py)
Solution 1:[1]
You are using the wrong division operator. hundredth = s\100 needs to be changed to hundredth = s/100.
You have the same problem in the rest of your code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Quint |
