r/learnpython • u/MadHedge • 6d ago
Fixing my skipped list
So I just posted a post and had to delete because I realized I fucked up and didn’t upload any code with it. I have a project in Python that I have to make. Mine is going to be a text adventure game and it keeps skipping the enmy list. It also just reloops regardless of if the user dies or not.
Here is the section of the code:
for i in range(len(loc)):
current_loc=loc[i]
current_dsrp=dsrp[i]
current_nos=nos[i]
current_enmy=enmy[i]
print("\nYou find yourself in,:" + current_loc + ".")
print(current_dsrp)
print(current_nos)
choice = input("\nDo you want to investigate? (Yes or No): ").lower()
while choice != "yes" and choice != "no":
print("You cower away and die of fear!")
else:
choice == "yes"
printItem(current_enmy)
conChoice = input("\nDo you wish to continue? (Yes or No): ").lower()
while conChoice != "yes" and conChoice != "no":
print("You curl in a ball and cry.")
if conChoice == "no":
conChoice == "no"
print("You have died from dehydration and fear!")
else:
print("You have escaped the killer!")
main()for i in range(len(loc)):
current_loc=loc[i]
current_dsrp=dsrp[i]
current_nos=nos[i]
current_enmy=enmy[i]
print("\nYou find yourself in,:" + current_loc + ".")
print(current_dsrp)
print(current_nos)
choice = input("\nDo you want to investigate? (Yes or No): ").lower()
while choice != "yes" and choice != "no":
print("You cower away and die of fear!")
else:
choice == "yes"
printItem(current_enmy)
conChoice = input("\nDo you wish to continue? (Yes or No): ").lower()
while conChoice != "yes" and conChoice != "no":
print("You curl in a ball and cry.")
if conChoice == "no":
conChoice == "no"
print("You have died from dehydration and fear!")
else:
print("You have escaped the killer!")
main()
0
Upvotes
4
u/atarivcs 6d ago
Please edit your post to correct the formatting.
Indentation is very important in python, and this code has none. We can't tell where the loops and if/then statements are supposed to start and end.
2
u/atarivcs 6d ago
When you say "it also just reloops", which loop do you mean?
The
for i in range(len(loc))loop?The
while choice != "yes" and choice != "no":loop?The
while conChoice != "yes" and conChoice != "no":loop?It might help if you posted some sample output so we can see exactly what the code is doing.
1
u/Rare-Pay9795 4d ago
looking at your code there are a few things beyond the missing break.
choice == "yes"andconChoice == "no"use two equals signs, which just compares and throws the result away, so those lines do nothing (you'd need a single = to assign, or more likely you just want to delete them). thewhile choice != "yes" and choice != "no"loops never ask for input again inside the loop, so a bad answer would print forever. usewhile choice not in ("yes", "no"):and put the input() call inside it. theelse:attached to that while loop always runs when the loop finishes, so printItem(current_enmy) fires even when they typed no, which is probably why it seems to skip around. replace it with a normalif choice == "yes":check after the loop, and when the player dies callreturnso the for loop stops.