Ill start off by saying im very much a beginner in coding and im working with an online course to learn. Unfortunately ive come up against an issue which i cant seem to find a work around.
im trying to read a line from a file and then assign it to a variable. im then asking for input from the user, and then (within a while loop) if that users input matches the variable to open up another file and follow the action.
here is my code currently:
user1 = open ("holiday.txt", "w")
user1.write ("Holiday Location: " + holiday_loc + "\n")
user1.write ("Total Price: £" + str(total_price) + "\n")
user1.write ("Total People: " + str(total_people) + "\n")
user1.close()
print ("Here are a list of commands")
commands = open ("commands.txt", "r")
# command_line 1 = show data
command_line1 = commands.readline()
# command_line2 = price PP
command_line2 = commands.readline()
print (command_line1 + command_line2)
commands.close()
cl1 = command_line1
cl2 = command_line2
answer = input ("What would you like to do? ")
while answer != "cl1" or answer != "cl2":
print("Im sorry, there is no such command")
answer = input("What would you like to do? ")
else:
if answer == cl1:
show_data = open ("holiday.txt", "r")
line1 = show_data.readline()
line2 = show_data.readline()
line3 = show_data.readline()
print (line1 + "\n" + line2 + "\n" + line3)
elif answer == cl2:
print (line2/line3)
So all of this code is fine up untill "What would you like to do " command, it asks for input but it user inputs cl1 or cl2 (or anything in fact) it just runs the while loop and asks the question again.
What i would like it to do is if user input either command as written in the command file (show data or price pp) to skip the first loop and start the second nested loop.
I hope that all made sense, any suggestion?
Thanks in advance.
Marc
edit: this has nothing to do with comparing variables, i think
edit: added while answer != "cl1" or answer != "cl2":
code still outputs:
What would you like to do? show data
Im sorry, there is no such command
What would you like to do? cl1
Im sorry, there is no such command
What would you like to do?