2016-08-30 3 views
0

Ich bin neu bei Python, und ich kann nicht herausfinden, wie dies funktioniert, es funktioniert einfach nicht. (Andere Antworten helfen mir nicht)Python IDLE 3.5 ungültiges Literal für int() mit Basis 10

Hier ist mein Code:

# 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() 

Und dann bekomme ich diesen Fehler, wenn ich es laufen.

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: ':' 

Kann jemand bitte meinen Code reparieren?

+0

Wenn Sie einen Brief als Eingabe zu fragen, es nicht zu einem Integer umgewandelt werden kann 'int' – gamda

+0

Warum zum Teufel Sie anrufen' int' wenn Sie haben den Benutzer gebeten, 'L',' R', 'B' oder' F' einzugeben? – user2357112

+0

Was ersetze ich Int dann? –

Antwort

0

Sie müssen directionchoice nicht zu einem int konvertieren.
direction sollte gleich directionchoice sein.
Dann testen, ob direction nicht in der gewünschten Auswahl ist:

if direction not in ['L', 'R','B', 'F']: 
Verwandte Themen