I am a python intermediate and tried to make a text based adventure game in python. In it there is a function called shop() which is executed whenever I type 's'.
buy_item = input('\nWhat would you like to buy? Enter \'n\' to close shop,\'e\' to equip something, \'1\' for dagger, \'2\' for short sword, \'5\' for leather armour and so on. ').lower()
possible_answers = ['1', '2', '3', '4', '5', '6', '7', '8', 'n', 'e']
while buy_item not in possible_answers:
print('Invalid answer')
buy_item = input('What would you like to buy? Enter \'n\' to close shop, \'e\' to equip something, \'1\' for dagger, \'2\' for short sword, \'5\' for leather armour and so on. ').lower()
if buy_item == '1':
if shop_items[0].get('dagger cost') > player['gold']:
print('Not enough gold!')
else:
player['weapons'].append('dagger')
player['gold'] -= shop_items[0].get('dagger cost')
print(f'You just bought dagger for {shop_items[0].get("dagger cost")}')
print(f'Gold: {player["gold"]}')
elif buy_item == 'n':
print('Thank you for visiting the shop. You can always come back by entering \'s\'.')
There is a lot more than that but this should be sufficient to answer this problem. It is working perfectly well but to buy like item 1 and item 2 both, first I will need to type 's', buy item 1 then again type 's' and buy item 2. I want it to stay on the screen until typed 'n' so I wont have to type 's' again and again to buy each item. If more code need then tell me and I will edit this to show full code.