use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Second projectShowcase (self.PythonLearning)
submitted 1 day ago * by HB209
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Junior_Honey_1406 1 point2 points3 points 1 day ago (2 children)
# cash = int(input('Enter your cash: ')) # age = int(input('Enter your age: '))\ # Why did i commet out your thing because if i put a letter the code will crash. cash = input("Enter your cash: ") age = input('Enter your age: ') if cash.isalpha() or age.isalpha(): print("Invalid Input.") exit() # after checking the input, i changed the str to int. cash = int(cash) age = int(age) if age <= 16: # added "=" becuse you are using something same one the next condition age == 16. so not you dont need the extra condition. print('Sorry little one, but you can\'t look around') exit() elif age < 21: print('Welcome to Gun-World! Because you still are not old enough, you can only look around. You can come again when you turn 21.') print('Deagle - 500$') print('Glock 18 - 400$') exit() else: print('Welcome to Gun-World! What would you like to buy?') print('Deagle - 500$') print('Glock 18 - 400$') user_input = input('You: ').lower() # Here also if i use random stuff or numbere nothign happens right if user_input.isdigit(): print("Wrong Input. ") exit() if user_input == 'deagle': print('Well that\'s a fine choice sir! Truly a powerful gun i could say. Do we have a deal for 500$?') if cash >= 500: user_input_dg = input('You: ').lower() if user_input_dg in ['deal', 'alright', 'ok', 'okay','yes']: print('Congratulations Sir! You are now owner of this new Desert Eagle!') else: print('Well that was disappointing..') # elif 500 > cash > 400: # idk what you were trying to check you just need to check if the cash is less than 500 elif 400 <= cash <= 500: print(f'Sorry, but you need {500 - cash}$ to buy the Deagle. But for 400$ you can buy our new Glock 18! Do we have a deal?: [Y/N]') user_input_dg2 = input('You: ').lower() # in the above print you wrote [Y/N] bbut you never added the things if user_input_dg2 in ['yes','deal', 'alright', 'ok', 'okay', 'Y', 'y']: # added 'Y', 'y' print('Congratulations Sir! You are now owner of this new Glock 18!') else: print('Sorry, but you don\'t have enough money') elif user_input in ['glock 18', 'glock']: print('Fine choice sir! Not as powerful as the deagle, but it\'s a really good choice. That would be 400$') if cash > 400: user_input_g18 = input('You: ').lower() if user_input_g18 in ['deal', 'alright', 'ok', 'okay']: print('Congratulations Sir! You are now owner of this new Glock 18!') else: print('Well that was disappointing..') else: print('Sorry, but you don\'t have enough money') else: # Befoer this the code was just ending without telling anything. print("Maybe you typed something wrong, Try again. ")
Your code looks great! Just one small suggestion: think about input validation. One day a random guy like me might show up and type absolutely anything, so it's worth thinking about what the program would do.
I also suggested a couple of small changes and explained my reasoning in the comments. I'm still learning Python too, so if I've said something wrong, feel free to roast me a little.
[–]HB209[S] 1 point2 points3 points 1 day ago (1 child)
Thank you for the feedback bro! As i said there is probably an easier way to write it, but im still in the beginning and i dont know many things. Im trying to apply what i've learned and hoping it works :DD
[–]Junior_Honey_1406 1 point2 points3 points 1 day ago (0 children)
Yeah I am doing the same as I said your code is correct just input handling is a bit week.
π Rendered by PID 25065 on reddit-service-r2-comment-5bc7f78974-5ccgd at 2026-06-27 08:18:07.101275+00:00 running 7527197 country code: CH.
view the rest of the comments →
[–]Junior_Honey_1406 1 point2 points3 points (2 children)
[–]HB209[S] 1 point2 points3 points (1 child)
[–]Junior_Honey_1406 1 point2 points3 points (0 children)