我的代码应该选择内部或外部存储器并打开它。我首先尝试将内部定义为零,将外部定义为1,以便在按0或1时输出可以是其中之一。
我还尝试从存储= {'internal:0,'external:1}中选择0或1作为值。我试图将其传递给该类,并通过按0或1来让程序内部或外部打开,但我不在打开它的阶段。
class Memory:
def __init__(self,internal,external):
self.internal = internal
self.external = external
def select(self):
while True:
try:
choose = int(input("For Internal Storage Enter 0, For External Storage Enter 1\n"))
print(choose)
break
except ValueError:
print("For Internal Storage Press 0, For External Storage Press 1")
except SyntaxError:
print("For Internal Storage Press 0, For External Storage Press 1")
finally:
pass
if self.internal = 0:
print("ok")
elif self.external = 1:
print('ookk')
else:
pass
card = Memory()
card.select()
我想要这个输出:
>>For Internal Storage Press 0, For External Storage Press 1
0
internal
或此输出:
>>For Internal Storage Press 0, For External Storage Press 1
1
external