- #1
member 428835
Hello
I have a script a13_roman2num.py that reads
and another script a12.py that runs
For some reason when I run a12.py the output prints 1904. Why is a12.py running the entire script a13_roman2num.py instead of just importing the function I'm asking for?
Thanks so much!
I have a script a13_roman2num.py that reads
Python:
def value(r):
if (r == 'I'):
return 1
if (r == 'V'):
return 5
if (r == 'X'):
return 10
if (r == 'L'):
return 50
if (r == 'C'):
return 100
if (r == 'D'):
return 500
if (r == 'M'):
return 1000
return
def romanToDecimal(str):
i = 0;
res = 0;
while i < len(str):
if i + 1 < len(str):
if value(str[i]) < value(str[i+1]):
res += value(str[i+1]) - value(str[i])
i += 2
else:
res += value(str[i])
i += 1
else:
res += value(str[i])
i += 1
return res
# DRIVER CODE
str = "MCMIV"
print(romanToDecimal(str))
and another script a12.py that runs
Python:
from a13_roman2num import value
For some reason when I run a12.py the output prints 1904. Why is a12.py running the entire script a13_roman2num.py instead of just importing the function I'm asking for?
Thanks so much!