0
我是新来的python,我无法弄清楚如何使这项工作,它只是不会工作。 (其他答案绝不会帮我)Python空闲3.5无效文字为int()与基地10
这里是我的代码:
# My First Python Game Thing
# Aka Endless Walking Simulator
game_temp1 = True
def choiceroom_thing1():
while game_temp1:
directionchoice = input('L(left)R(Right)B(Backwards)F(Forwards)')
direction = int(directionchoice)
if direction in ['L', 'R','B', 'F']:
game_temp1 = False
if direction == "L":
print ('You went Left!')
if direction == "R":
print ('You went Right!')
if direction == "B":
print ('You went Backwards!')
if direction == "F":
print ('You went Forwards!')
game_temp1 = True
room_count = room_count + 1
choiceroom_thing1()
print ('Hello Jeff...')
print ('Heres my first game')
print ("Adventure Game")
input("Press Any Key To Continue...")
room_count = 1
while game_temp1:
directionchoice = input('L(left)R(Right)B(Backwards)F(Forwards)')
direction = int(directionchoice)
if direction in ['L', 'R','B', 'F']:
game_temp1 = False
if direction == "L":
print ('You went Left!')
if direction == "R":
print ('You went Right!')
if direction == "B":
print ('You went Backwards!')
if direction == "F":
print ('You went Forwards!')
game_temp1 = True
room_count = room_count + 1
choiceroom_thing1()
,然后当我运行它,我得到这个错误。
Traceback (most recent call last):
File "C:/Users/Owner/Desktop/PythonProjects/Blah From Book.py", line 27,
line 27, in <module>
direction = int(directionchoice)
ValueError: invalid literal for int() with base 10: ':'
有人可以修复我的代码吗?
你问了一个字母作为输入,它不能被转换为'int' – gamda
见鬼,为什么你叫'int'时你问用户输入'L','R','B'还是'F'? – user2357112
然后我用什么来取代int? –