class Planet:
def __init__(self, name, radius, system, gravity):
self.name=name
self.radius=radius
self.gravity=gravity
self.system=system
def orbit(self):
return(f'{self.name} is orbiting in the {name} system')
planet_list=[]
while True:
name = input('Enter the Planet\'s name: \n')
radius = int(input('Enter the Planet\'s radius: \n'))
gravity = int(input('Enter the Planet\'s gravity: \n'))
system = input('Enter the Planet\'s system: \n')
sub_list=[name,radius,gravity,system]
planet_list.append(sub_list)
again=input('\nAdd another planet? (Y/N): ')
if again.startswith('y') or again.startswith('Y'):
continue
elif again.startswith('n') or again.startswith('N'):
break
else:
print('I didn\'t quite catch that...')
continue
def planet_intro(dictionary):
for world in planet_list:
i=0
print(f'\nPlanet: {planet_list[i][0]}\nRadius: {planet_list[i][1]}\nGravity: {planet_list[i][2]}\nSystem: {planet_list[i][3]}\n')
i+=1
planet_intro(planet_list)
我在这方面已经有一段时间了,但无论出于何种原因,我都无法声明一个整数并将该变量用作索引的值。我今天刚开始使用 Java,所以这可能是一个非常简单的修复方法,但我还没有弄清楚。
因此,如果我运行它,它会为 中的多个列表重复相同的数据planet_list,而不迭代索引的值(更改打印的数据)。
慕侠2389804
饮歌长啸
相关分类