while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") userChoice = input()
if(userChoice == "1"): print("What item do you want to add to the backpack?") itemToAdd = input() itemsInBackpack.append(itemsInBackpack) print('you have just added ' + itemToAdd + ' to your backpack')
if(userChoice == "2"): print("What item do you want to check to see if it is in the backpack?") itemToCheck = input() for i in range(len(itemsInBackpack)): if itemToCheck in itemsInBackpack: print("Already in backpack") else: print('nope') print('Items in backpack:{0}'.format(', '.join(itemsInBackpack)))
1) install gentoo 2) use the stupid question thread / daily programming thread 3) use code blocks ([ c o d e ] + [ / c o d e ], without spaces)
Landon Flores
is this the no code tags meme?
Jose Jackson
>his while statement doesn't have a condition for it to stop
Oliver Jones
i couldnt figure it out too, guess im more retarded than OP
Gavin Long
Can someone just ban you fuckers? READ THE STICKY when you are posting code.
Are you just trolling because it is literally impossible to see what is wrong with your code when you post without code blocks? This is likely easy to fix, but you don't have code blocks. Are you deliberately doing this?
In that case, nice meme. It's pretty infuriating
Michael Russell
How does one post with code block?
Jeremiah Nguyen
The problem is your indentation. There is nothing in the loops, how you get it to run at all is a miracle.
Christopher Jenkins
first of all, do like said, and put your code inside the code tags. Second of all, your while loop needs to become false at some point. So you could make it false during the end of each condition. Something like this:
if(poop peepee) //do your shit; variable = false;
Robert Brooks
as someone posted before...
use code blocks ([ c o d e ] + [ / c o d e ], without spaces)
Nathaniel Barnes
Don't spoonfeed him when it's literally in the sticky
Christian Wilson
Put your code inside
[/code.] (Just remove the period for it to work)
Ayden Stewart
Have you not learnt anything from previous thread? You NEED to put your code inside code tags, otherwise whitespace is not preserved, and it so happens, that whitespace matters in python
while True: print('Would you like to:') print('1. Add an item to the backpack?') print('2. Check if an item is in the backpack?') print('3. Quit') userChoice = input()
if userChoice == '1': print('What item do you want to add to the backpack?') itemToAdd = input() itemsInBackpack.append(itemsInBackpack) print('you have just added ' + itemToAdd + ' to your backpack')
if userChoice == '2': print('What item do you want to check to see if it is in the backpack?') itemToCheck = input()
if itemToCheck in itemsInBackpack: print('{0} is in backpack'.format(itemToCheck)) else: print('{0} is not in backpack'.format(itemToCheck))
if userChoice == '3': break
print('Items in backpack: {0}'.format(', '.join(itemsInBackpack)))
Since whitespace is important in python it's basically impossible to read this without code blocks.
Ryder White
if userChoice == '1': print('What item do you want to add to the backpack?') itemToAdd = input() itemsInBackpack.append(itemsInBackpack) print('you have just added ' + itemToAdd + ' to your backpack')
You are not adding an item to the list...
itemsInBackpack.append(itemsInBackpack)
you are adding the whole original list into itself.
it should be
itemsInBackpack.append(itemToAdd)
Oliver Davis
Thanks for pointing it out! I missed that whilst copying from OP.
Josiah Brown
Why are you appending the list back on to itself? Should enter you be appending it with thee user input variable?
Carson Martinez
I don't see any problems after doing this.
Jackson Diaz
I got a problem when I was checking to see if an item was in the back pack, the out put was
"What item do you want to check to see if it is in the backpack? book Already in backpack Already in backpack Already in backpack Already in backpack"
Nathan Perry
I don't get the problem...
Is it appended like this user did? Because THAT works flawlessly apart from the "itemToAdd"-bug
Jason Lewis
indentated, not appended
Mason Ortiz
Because it was in a loop. Do what's given to you in
Aiden Powell
you don`t need for loop to check the list, it prints 7 times same thing
print("What item do you want to check to see if it is in the backpack?") itemToCheck = input() if itemToCheck in itemsInBackpack: print("Already in backpack") else: print('nope') print('Items in backpack:{0}'.format(', '.join(itemsInBackpack)))