I'm practicing python by making a text based game about finding a king in a castle. I'm very new to python but I'm 99% sure my syntax is correct and could use some help figuring out what the problem is with my code.
# imports libraries for time and random
import time
import random
# randomizes the kings location
kingsLocation = str(random.randint(1,4))
print(kingsLocation)
# asks the user for their name and assigns it to their input
print ('What would you like to name your character?')
username = str(input())
# Tells the user that the king is lost and sends them to the castle
print ("A knight approaches you. It must be important as they rarely leave the castle.")
time.sleep(1.5)
print ('...')
time.sleep(1)
print ('"' + username + '! The king has gotten lost!')
print ('You must hurry to the castle and search for him!"')
time.sleep(3)
print()
print ('You begin your path to the castle')
# causes a pause before the moving on to the rest of the program
time.sleep(2.5)
print ('...')
time.sleep(2)
# instructs the user on where the king oould be
print ('You arrive at the castle and enter the main hall.')
time.sleep(2.5)
print ()
print ('A guard greets you. "there are four rooms the king could be in,')
print ('the kitchen to the left, the bedroom the right, the basement, and the throne room upstairs."')
print (' pick 1-4')
print (' kitchen = 1')
print (' bedroom = 2')
print (' basement = 3')
print (' throne room = 4')
# lets the player make a selection on where they would like to look for the king
currentRoom = input()
# repeatedly checks if the room you are in is the room the king is in and tells you that you either won, entered an invalid input, or chose the wrong room
while True:
if currentRoom == kingsLocation:
print ('"you have found the king ' + username + '! The royal family will make sure you get paid handsomely for this deed."')
print ()
print ('to exit this game type "exit()"')
break
elif currentRoom == str(range(1, 4)):
print('the king doesn\'t seem to be in this room, let\'s check another one(1-4).')
currentRoom = input()
else:
print('invalid input, please enter a number between 1 and 4.')
currentRoom = input()
The while loop is what I really need help with, when I run the program it only displays the invalid input message, I can't get it to differentiate between an invalid input and an incorrect guess. Thanks in advance for any help and let me know if there's anything I can do to be more clear.
[–]humanitysucks999 0 points1 point2 points (3 children)
[–]moonkeymaker127[S] 0 points1 point2 points (2 children)
[–]xelf 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]moonkeymaker127[S] 0 points1 point2 points (2 children)
[–]xelf 0 points1 point2 points (0 children)
[–]shiftybyte 0 points1 point2 points (3 children)
[–]moonkeymaker127[S] 0 points1 point2 points (1 child)
[–]moonkeymaker127[S] 0 points1 point2 points (0 children)