Thursday, July 26, 2018

python - I need to get continuous input for this but when I use a while loop it breaks

I try to use a while loop after the prints in the main_function but the input only goes to "What do you want to buy" and breaks afterwards. Any tips or solutions??



I have tried to make an input function as such:
def inp():
global use
use = input('/>> ')
inp()
And all that function in my main_func function after making the use variable global. This is python 3.7.1, I just can't figure out why it won't go any deeper that the first question.





import sys
import os


inventory = []
stock = ['spoon', 'fork']





def main_func():
print('Welcome to the store, some ground rules before we begin:\n')
print('1)No running, plz\n2)No stealing, your bad if you steal!!\nEnjoy')
print('Commands: Sell, Buy, Exit')

running = True
while running == True:
inp = input("/>> ")




if inp == 'Buy' or inp == 'B' or inp == 'buy':
print('What would you like to buy?: ')
if inp == 'spoon' or inp == 'Spoon':
stock.remove('spoon')
inventory.append('spoon')
if 'spoon' not in stock and 'spoon' in inventory:
print('Successfully bought a spoon!')

elif inp == 'fork' or inp == 'Fork':
stock.remove('fork')
incentory.append('fork')
if 'fork' not in stock and 'fork' in inventory:
print('Successfully bought a fork')
elif inp == 'Sell' or inp == 'sell' or inp == 'S':
print('What would you like to sell?: ')
if inp == 'spoon' or inp == 'Spoon' or inp == 'S':
if 'spoon' not in inventory:
print("You can't sell something you don't have")

if 'spoon' in inventory:
inventory.remove('spoon')
stock.append('spoon')
print("Successfully sold "+inp+".")
elif inp == 'fork' or inp == 'Fork' or inp == 'F':
if 'fork' not in inventory:
print("You can't sell something you don't have")
if 'fork' in inventory:
inventory.remove('fork')
stock.append('fork')

print('Successfully sold Fork..')
elif inp == "Exit" or inp == 'exit' or inp == 'quit':
sys.exit()

main_func()



'''I know the code is poorly structured and bad, I just want to experiment with something'''




There are no error messages that pop up but after it ask "What would you like to buy" I input one of the items and it does nothing, it still gets input but doesn't react to the item I put in. Ex:



"What would you like to buy?: "
/>> spoon #Press enter#
/>> #It gets input again and does nothing#

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...