I recently started programming in Python and I made a small shop. I want it to ask you if you want to buy anything else, and if the answer is yes, it will loop to the start of the program. I have tried other solutions but none of them worked. I'm using Python 3.x. If you want to take a look here it is:
import datetime
now = datetime.datetime.now()
hours = now.hour
if hours < 12:
greeting = "Good morning"
elif hours < 15:
greeting = "Good afternoon"
elif hours < 18:
greeting = "Good evening"
elif hours < 24:
greeting = "Good night"
print('{}!'.format(greeting),)
a = input('would you like to buy a console? (y/n) ')
if a == 'y':
consoleQ = input('What console would you like? (ps4/switch/xboxone) ')
if consoleQ == 'ps4':
print('Ok! Here is your Ps4! Have a good day!')
elif consoleQ == 'xboxone':
print('Ok! Here is your Xbox One! Have a good day!')
elif consoleQ == 'switch':
print('Ok! Here is your Switch! Have a good day!')
exit(print('Have a {}!'.format(greeting),))
elif a == 'n':
print('Okay, have a good day!')
exit()
I have tried using this to loop: (didn't work)
loop = input('Would you like anything else? (y/n)')
while loop == 'y':
a = input('Would you like to buy a console? (y/n)')
I have just started, so please don't be harsh. I know that I don't REALLY know a lot of stuff, after all, this is my second week programming. Thanks in advance!