我对编程非常陌生,所以请帮助我!你知道吗
我希望在命令行中打印roman_numeral_map
的所有值,但是我得到了很多错误。你知道吗
这是我的密码:
class roman1:
roman_numeral_map = (('M', 1000),
('CM', 900),
('D', 500),
('CD', 400),
('C', 100),
('XC', 90),
('L', 50),
('XL', 40),
('X', 10),
('IX', 9),
('V', 5),
('IV', 4),
('I', 1))
def to_roman():
'''convert integer to roman numeral'''
for numeral, integer in roman_numeral_map:
print(numeral, integer)
if __name__ == '__main__':
self.roman = roman1()
roman.to_roman
这是我得到的回溯(谢谢)!你知道吗
Traceback (most recent call last):
File "/Users/michaelmatos/PycharmProjects/diveintopython3/roman1.py", line 4, in <module>
class roman1:
File "/Users/michaelmatos/PycharmProjects/diveintopython3/roman1.py", line 27, in roman1
self.roman = roman1()
NameError: name 'roman1' is not defined
如果您只是想遍历元组并打印出每个选择,那么您可以尝试这样做。你知道吗
很高兴能看到一个你想要的输出的例子。你知道吗
像这样声明你的类只是为了开始。你知道吗
然后实例化roman1类的一个实例。你知道吗
你的代码有一些问题,我在下面用内联注释修复了它们。你知道吗
重要的是,leading whitespace is significant in Python,您需要use ^{} 来引用实例变量和方法。你知道吗
See it run!你知道吗
一个改变了的班级:
相关问题 更多 >
编程相关推荐