【发布时间】:2020-08-24 04:38:18
【问题描述】:
所以我想开发基本代码,但我被困在这里。我知道我必须在 Bootcamp 类中调用该函数,但不知道如何调用。当输入作为训练营给出时,我想打印类训练营中的内容。帮助表示赞赏。
class match_start:
def choose_land(self):
print('You are in the plane. CHoose where to land')
land_area = input('->')
if land_area == 'bootcamp':
return 'Bootcamp'
elif land_area == 'docks':
return 'Docks'
else:
print('landed with bots')
class Bootcamp:
def bootcamp(self):
print ('Bootcamp it is')
class Docks:
def docks(self):
print('Docks it is')
x = match_start()
x.choose_land()
Output --
You are in the plane. CHoose where to land
->bootcamp
PS C:\Users\User\Downloads\New folder (2)\Practice>
PS - 我是编码和从 Zed Shaw 的 Learn Python the hard way 学习的初学者,所以请提出任何改进我的编码的建议。这也是我关于 stackoverflow 的第一个问题,也避免了愚蠢的 pubg 参考。
【问题讨论】:
-
你既不打印
x.choose_land()的结果,也不使用Bootcamp类。你为什么希望看到他们的字符串被打印出来? -
我猜我在
land_area = input('->') if land_area == 'bootcamp': return 'Bootcamp'使用了Bootcamp类
标签: python-3.x string python-class pubg