Skip to content
← Back to Community
how to make a shop in python
Profile icon
bottlesandcaps

starting

welcome to my tutorial today i am going to show you the following functions that are needed in making a shop:

  • print("")
  • input()
  • if
  • for
  • else:

so how to start

so for this to work what you want to use is a print statment to welcome people to the shop just like this:

print("welcome to my shop would you like to buy anything?")

by doing that the program will allow you to print whats inside your quotations when you run it.


cash

so in order for this to actually work you need your money to be called by using something like

  • gold
  • cash
  • coins
  • etc
    so under that print statement from earlier type this right under it:
gold = 100

that 100 is telling you how much gold you have to spend


inputs

so when you ask that print statement it wants you to answer the question so for that to happen do this under gold:

answer = input()

this will allow the user to input an answer of yes or no.
then after that what you want to put it this:

if answer == "yes": print("would you like to buy a shield or a sword?")

so far your code should look like this if you did it correctly:

print("welcome to my shop would you like to buy anything") gold = 100 answer = input() if answer == "yes": print("would you like to buy a shield or a sword?")

inputs for shield or sword

so next up is more input statements so under the above code what u need to do is this:

gear = input() if gear == "sword": if gold >= 10: print("you have purchased a sword!")

by doing that it allows yu to buy a sword but where it says if gold>= 10: means that if you have less than 10 gold you cant buy it but if u have more than 10 u can buy it.


removing gold

so after that when u purchased the sword you want to make it take away the gold u spent on the sword so to do that you want to do this:

gold -= 10 print("you now have", + gold)

this will take away gold from your balance and allow you to see how much u have left. now if you dont have enough gold you want to do this:

else: print("you dont have enough gold")

so now for the shiled you basically want to do the same exact thing:

gear = input() if gear == "shield": if gold >= 10: print("you have purchased a shield!") gold -= 10 print("you now have", + gold) else: print("you dont have enough gold")

that should be all you would need and your final code should look like this:

print("welcome to my shop would you like to buy anything") gold = 100 answer = input() if answer == "yes": print("would you like to buy a shield or a sword?") gear = input() if gear == "sword": if gold >= 10: print("you have purchased a sword!") gold -= 10 print("you now have", + gold) else: print("you dont have enough gold") gear = input() if gear == "shield": if gold >= 10: print("you have purchased a shield!") gold -= 10 print("you now have", + gold) else: print("you dont have enough gold")

and yeah after that enjoy my tutorial

Voters
Profile icon
Thomastrain06
Profile icon
JessicaWard1
Profile icon
ParthChawla
Profile icon
decomp
Profile icon
jeremiahlacoder
Profile icon
JKE010
Profile icon
Mustafakhand
Profile icon
traves
Profile icon
figglediggle
Profile icon
Honestly
Comments
hotnewtop
Profile icon
brienmoncy
Profile icon
brienmoncy

proof it doesn't work

Profile icon
sacredgames

Hi

Profile icon
bottlesandcaps

@JKE010 wassup long time no see

Profile icon
JKE010

long time no see indeed, how've ya been?
I took a break from repl.it and programming in general, I lost motivation :/
Great tutorial tho!
@bottlesandcaps

Profile icon
JKE010

check out the program I shared you ;) @bottlesandcaps

Profile icon
bottlesandcaps

@JKE010 hey man I’m back in business we should see what we should do sometime if ur down I’m down to do it with you man

Profile icon
JKE010

it's been a while man, how you doing?
@bottlesandcaps

Profile icon
bottlesandcaps

@JKE010 I’m doing pretty good what about u

Profile icon
JKE010

pretty good, thank you very asking :) just chillin and enjoying summer @bottlesandcaps

Profile icon
bottlesandcaps
Profile icon
JKE010

@bottlesandcaps hey man! hope everything's goin well. also when are we gonna actually work on something LOL

Profile icon
bottlesandcaps

@JKE010 yay man whenever we can I’m trying to make time on this app again but ya know ima be more active now so let me know if u wanna work on something and also remember our game hehe kinda got away from us lol

Profile icon
bottlesandcaps

@JKE010 yooooo we should finish our game bro like it’s been about 7 months since we did anything on it we should finish it

Profile icon
ParthChawla

Ok, I appreciate this @bottlesandcaps

Profile icon
WolfsonJAcob

the else: part is erroing @LTI2

Profile icon
bottlesandcaps

@WolfsonJAcob wait what

Profile icon
PlsDont

@WolfsonJAcob for me it works perfectly fine! But instead of a sword and shield i made an animal shelter because I love animals https://repl.it/@PlsDont/animal-shelter#main.py

Profile icon
bottlesandcaps

@PlsDont hey want me to show you how to add more selections for you

Profile icon
PlsDont

sure! @bottlesandcaps one question though. how do you make it so that once you buy something you can buy another thing?

Profile icon
bottlesandcaps

@PlsDont invite me and ill show u

Profile icon
PlsDont

how do i do that? @bottlesandcaps

Profile icon
bottlesandcaps

@PlsDont what invite

Profile icon
bottlesandcaps

@LTI2 ill be on the monopoly one

Profile icon
bottlesandcaps

@LTI2 ill be on the monopoly one

Profile icon
JBloves27

Pretty cool tutorial, maybe add more options to the tutorial?

Profile icon
bottlesandcaps

@JBYT27 ok and thanks

Profile icon
JBloves27
Profile icon
bottlesandcaps

@LTI2 whanna get on the monopoly thing

Profile icon
bottlesandcaps

@JKE010 wanna get on our game

Profile icon
bottlesandcaps

@TsunamiOrSumth wanna start making a game for the blue team

Profile icon
TsunamiOrSumth

@bottlesandcaps im making one myself.

Profile icon
bottlesandcaps
Profile icon
bottlesandcaps

@InvisibleOne
wanna start a python prject with me for the blue team

Profile icon
InvisibleOne

What kind of project? @bottlesandcaps

Profile icon
bottlesandcaps

@InvisibleOne a game thing lol

Profile icon
InvisibleOne

Yeah but what kind of game? @bottlesandcaps

Profile icon
bottlesandcaps

@InvisibleOne umm text based python umm adventure game roll play or like a monopoly game

Profile icon
InvisibleOne
Profile icon
bottlesandcaps

@InvisibleOne want me to make it or u

Profile icon
InvisibleOne

I invited you to a repl @bottlesandcaps

Profile icon
InvisibleOne


Profile icon
bottlesandcaps

@InvisibleOne hey r u there

Profile icon
adl212

@InvisibleOne uhh anyone can use the link lol

Profile icon
bottlesandcaps
Profile icon
InvisibleOne

Fixed it @adl212