Been using easygui in python to make gui boxes for various different system applications for windows over the past few days. What I want to know is, why doesn't my code work? It looks the same as the code that was working before? The program is a game launcher, and I shall be making one identical to this but working (with different, LAN compatible games) for people to select the game from the list. Looked on stack overflow and found somebody with a similar issue, however I don't believe his resolution would apply to my script. Will post code below,
thank you,
Matthew
import easygui as eg
import os
def menu():
msg="Please select a game:"
title="Select Game!"
choices=["Batman Arkham City", "Tomb Raider", "TESV Skyrim", "State of decay - Early Access", "Critical Strike Portable", "Terraria", "Doom", "Halo","Minecraft"]
reply=eg.buttonbox(msg,title,choices)
if choices=="Batman Arkham City":
batman()
elif choices=="Tomb Raider":
tomb()
elif choices=="TESV Skyrim":
skyrim()
elif choices=="State of decay - Early Access":
state()
elif choices=="Critical Strike Portable":
crs()
elif choices=="Terraria":
terr()
elif choices=="Doom":
doom()
elif choices=="Halo":
halo()
elif choices=="Minecraft":
minecraft()
def batman():
os.system('"C:\Program Files (x86)\Black_Box\Batman Arkham City\Binaries\Win32\BatmanAC.exe"')
menu()
def tomb():
os.system('"C:\Program Files (x86)\Tomb Raider\TombRaider.exe"')
menu()
def skyrim():
os.system('"C:\Program Files (x86)\The Elder Scrolls V Skyrim\SkyrimLauncher.exe"')
menu()
def state():
os.system('"C:\Games\State of Decay Early Access\StateOfDecay.exe"')
menu()
def crs():
os.system('"C:\Program Files (x86)\CS Portable\a.exe"')
menu()
def terr():
os.system('"C:\Games\Terraria\Terraria.exe"')
menu()
def doom():
os.system('"C:\DOOMWADS\doom.wad"')
menu()
def halo():
os.system('"C:\Program Files (x86)\Halo Combat Evolved\Halo.exe"')
menu()
def minecraft():
os.system('"C:\Games\minecraft.exe"')
menu()
menu()
Stack overflow has messed up my indents! Please assume these are correct as they are.
It's the backslashes that are causing the problem. Python interprets these itself, e.g. \n is a new line character.
Change them either to forward slashes, or to double backslashes.
os.system('"C:/DOOMWADS/doom.wad"')
I have fixed it.... Sorry for wasting anybodies time. The backslashes are fine because they are in '""', however in the menu section is "if choices=="game"" whereas it should be, "if reply=="game"". Thanks for the help! :)
Related
So, a while ago I started a project for educational and entertainment purposes on creating a Python based interaction story.
I wrote the code snippet below but I'm confused about something. (Bear in mind I'm new to Python so if it's something simple don't be rude please) In the snippet below I can call the function before I write it. For example, the first one I call upon is "path_1_1()" which then prints the path_1_1() function below. I'm confused as to why I can't do this in other Python programs and scripts? Because it gives me a NameError and says the variable is not defined.
def meadow():
print("You are in a tall grassy meadow\n\
there is lots of grass all around you\n\
however there are 2 paths\n\
the Train Rail Path\n\
or the Forest Path..")
meadow_choice = input("Which path will you choose? : ")
if meadow_choice =="Train Rail" or meadow_choice == "Train Rail Path" or meadow_choice == "train rail" or meadow_choice == "train rail path":
print("You've chosen the Train Rail Path")
path_1_1()
elif meadow_choice =="Forest Path" or meadow_choice == "forest path" or meadow_choice == "Forest" or meadow_choice == "forest":
print("You've chosen the Forest Path")
path_1_2()
else:
print("Woops, that's not a choice, try again.")
meadow()
# Train Rail Path 1.1
def path_1_1():
print("You walk up the train rail, cautious of\n\
oncoming trains. As you look around you spot a\n\
Small Note, and a Large hole..")
path_1_1_choices =input("Which would you like to investigate, the Small Note, or the Large Hole? : ")
if path_1_1_choices == "Small Note" or path_1_1_choices == "small note":
print("You've chosen to investigate the Small Note")
path_2_2_1()
elif path_1_1_choices == "Large Hole" or path_1_1_choices == "large hole":
print("You've chosen to investigate the Large Hole")
path_2_1_1()
else:
print("Woops, that's not a choice, try again.")
path_1_1()
Simply put, when you just define a function, you can call another function that comes later in the code.
However, when you call and execute the function, the called function should be pre defined.
def function_a():
function_b()
return 0
def function_b():
pass
This is valid.
function_a()
def function_a():
pass
This raises NameError, since function_a() was called before it was defined.
Python reads line one by one so when you call a fonction before writing it raises a NameError. However defining a fonction using def don't run any code, it only indicates to Python that the function exists and can be call further. So you can define all your functions first and, after that, call them without worrying about the order in which they are called.
I'm making a text-based game, which is based largely in if-, elif- and else-statements. However, I also use while loops for different "areas" within the game. (Play_loop, Main_loop, Shop_loop, Fish_loop, etc.).
Lately I've implemented admin commands which I use in-game to change things on the go, and I want these to be available in every loop. I also have some general commands which I want to be available (help, leave, quit, logout, go to another area, check inventory, etc.).
The issue I'm facing is knowing that duplicated code should be avoided, but i'm wondering if this is necessary in this situation. I've already made many functions to make each command code pretty short, about 2-15 lines in general.
Should I add the code blocks into functions that do the same thing, and then just repeat the function, or should I just keep it as is? Or maybe I should do something else that I havent even thought about?
Example code:
elif command == '/user info':
if user.admin:
print(f'User-list: {users}')
who = input('Name of user: ').strip()
who_user = admin_load_user(who, users)
if who_user:
print(who_user.info())
print(who_user.display_inv())
else:
print(DNEError)
else:
print(PError)
elif command == '/add coins':
who = input('Who gets coins? ').strip()
amount = int(input('How much? ').strip())
admin_add_coins(who, amount, users)
save_users(users)
Code that is repeated should typically be put into functions, so that you have better overview and control over what they are doing. There you can also easily give them default arguments and expand on the code without bloating the main function of your program.
Here is a concise argument for using functions. It's written for C but applies to python as well.
Then, as Jason Chia pointed out, you should consider thinking about building your game into classes, as they solve some of the problems you mentioned and generally are an important control instrument for bigger programs where you need to coordinate different states (e.g. changing something in a room based on the player's actions).
This tutorial could help with that.
Does that about answer your question?
You should use decorator style to do it nice to read and write.
get inspiration here:
def requires_admin(f):
def wrapper(f):
#wraps(f)
def wrapped(*args, **kwargs):
#if not admin:
#return render_template('error.html')
return f(*args, **kwargs)
return wrapped
return wrapper
#app.route('/admin/action')
#requires_admin
def AdminAction():
whatyouwant()
I am fairly new to python itself AND this forum.
I looked before if I found my problem here but haven't found a similar question before.
So I am currently working on a very very basic Tamagotchi and it has some sort of "easter egg- end credits".
It's a simple ascii (I think it's called that) copy pasta that repeats itself over and over, so it appears to be moving.
I use Pycharm, inside that if I hit Start it shows the copy pasta perfectly well.
But when I start the script outside the pycharm it only shows small Questionmark squares.
Specs:
Python 3
Pycharm
Windows 10
Hopefully someone can help me!
Also sorry if I said something wrong I am new :(!
achievement = True
while achievement == True:
clear()
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣠⣶⣶⣤⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣾⣿⣿⣿⣿⣿⡞⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣿⣿⣿⣿⣿⣿⡿⢃⡀⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⢿⣿⣿⣿⣿⣿⣿⣿⣧⡀⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢈⣽⣿⣿⣿⣿⣿⣿⣿⢿⣷⣦⣀⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣸⣿⣿⣿⣿⣿⣿⣿⣿⠄⢉⣻⣿⡇⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢠⣿⣿⡉⣀⣿⣿⣿⣿⣋⣴⣿⠟⠋⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣏⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⢀⣀⣼⣿⣿⣿⣿⣿⣿⠿⢿⣿⣿⣿⣿⣿⣮⡠⠄⠄⠄⠄")
print("⠄⠄⠄⠄⢰⣾⣿⣿⡿⠿⠛⠛⠛⠉⠄⠄⠄⠄⠙⠻⢿⣿⣿⣿⣶⣆⡀⠄")
print("⠄⠄⠄⠄⠄⠹⣿⣿⣦⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢉⣿⣿⣿⣿⣿⠂")
print("⠄⠄⠄⠄⠄⠄⠈⢿⣿⣇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣴⣾⣿⡿⠟⠉⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠂⢿⣿⣥⡄⠄⠄⠄⠄⢀⣠⣶⣿⣿⠟⠋⠁⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⣀⣤⣾⣿⣿⣷⣿⣃⡀⢴⣿⣿⡿⣿⣍⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠈⠉⠉⠉⠉⠉⠉⠉⠄⠄⠄⠉⠙⠛⠛⠛⠛⠂⠄⠄⠄⠄⠄")
sleep(1.25)
clear()
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⠄⣠⣶⣶⣷⣿⣶⡊⠄⠄⣀⣤⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⣀⣴⣶⣾⢿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⡏⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⢸⣿⡍⠁⠄⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠁⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣼⣿⣿⣿⣿⣿⣿⣿⠏⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣿⣿⣿⣿⣿⣿⣿⡿⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣿⡿⠋⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠻⣿⣿⣿⣿⣡⣶⣶⣄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⣀⣀⣠⣴⣦⡤⣿⣿⣿⣿⡻⣿⣿⡯⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡟⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⢻⣿⣿⡏⠉⠙⠛⢛⣿⣿⣿⣿⠟⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⢿⣿⡧⠄⠄⢠⣾⣿⣿⡿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠈⣿⣿⣄⣼⣿⣿⣿⠏⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠸⡿⣻⣿⣿⣿⣿⣆⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⣿⣻⠟⠈⠻⢿⣿⣿⣆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠿⠍⠄⠄⠄⠄⠉⠻⣿⣷⡤⣀⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⢻⣿⡿⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣿⡯⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠸⠃⠄⠄⠄⠄⠄⠄⠄")
sleep(1.25)
clear()
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⢠⣴⣧⣤⣴⡖⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⣰⣿⣿⣿⣿⣿⣷⣀⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⡄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠈⠘⠻⢿⣿⣿⣿⣿⣿⣿⣿⣆⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⢤⣴⣦⣄⣀⣀⣴⣿⡟⢿⣿⡿⣿⣿⣿⣿⣿⣿⡄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠉⠉⠙⠻⠿⣿⡿⠋⠄⠈⢀⣀⣠⣾⣿⣿⣿⣿⣿⡄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠉⠋⠉⠉⠁⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠈⠛⠛⣿⣿⣿⣿⣿⣿⣇⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⢀⣠⣶⣿⣿⠿⢛⣿⣿⣿⣿⣷⣤⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⣶⣷⣿⣿⡉⠄⠄⠄⠄⠉⠉⠉⠉⠉⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠘⠛⠟⢿⣤⣤⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
sleep(1.25)
clear()
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣤⣄⠄⡀⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣴⣿⣿⣿⣿⣷⡒⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⡀⣹⣿⣿⣿⣿⣿⣯⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣀⣀⣴⣿⣿⣿⣿⣿⣿⠿⠋⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⢀⣀⣤⣶⣾⠿⠿⠿⠿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄")
print("⠄⡶⣶⡿⠛⠛⠉⠉⠄⠄⠄⠄⢸⣿⣿⣿⣿⣿⣿⣿⠃⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠘⠃⠄⠄⠄⠄⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⡟⠁⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⣤⣾⣷⣿⣿⣿⣿⡏⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⢀⣤⣴⣾⣿⣿⣿⣿⡿⠛⠻⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠸⣿⣿⣿⣿⠋⠉⠄⠄⠄⠄⣼⣿⣿⡿⠇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠈⠻⣿⣿⣆⠄⠄⠄⠄⠄⣿⣿⣿⣷⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠻⣿⣿⣆⡀⠄⠄⠈⠻⣿⣿⣿⣦⡄⠄⠄⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⣀⣌⣿⣿⣿⣦⡄⠄⠄⠄⠙⠻⣿⣿⣦⣀⠄⠄⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠈⠉⠉⠉⠉⠉⠁⠄⠄⠄⠄⠄⠄⠄⠘⠻⣿⢿⢖⠄⠄⠄⠄⠄")
print("⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠉⠉⠁⠄⠄⠄⠄⠄")
sleep(1.25)
clear()
and here a screenshot of what I see when I run it outside pycharm:
Struggling to work out why python complaining at line 4:
import sys
import re
problem = input("What is wrong with your mobile device?").lower
water = re.search(r'water', problem)
screen = re.search(r'screen', problem)+ re.search(r'smashed',problem)or re.search(r'cracked',problem)+ re.search(r'display',problem)
software=re.search(r'software',problem)+ re.search(r'program',problem)
keypad=re.search(r'keypad',problem)+ re.search(r'keyboard',problem)+ re.search(r'text',problem)
speakers=re.search(r'sound',problem)+ re.search(r"can't here",problem)+ re.search(r'cant hear',problem)
microphone=re.search(r'microphone',problem)+ re.search(r'cant hear me',problem)+ re.search(r"can't hear me",problem)
battery=re.search(r'battery',problem)+ re.search(r'swollen',problem)
charger=re.search(r'Charger',problem)+ re.search(r'charge',problem)+ re.search(r'charging',problem)
if water:
print("If your phone has suffered water dammage there is not much you can do, it is recomended that you buy a new phone")
sys.exit
elif screen:
print("If your screen is cracked then it is recomended that you get it repaired this is not too expensive.")
sys.exit
elif software:
print("If you have a software issue then contact the product manurfacture, they are the only ones qualified to fix this.")
sys.exit
elif keypad:
print("Clean your keypad with a wetwipe, do not get the charger port or jack port wet.")
sys.exit
elif microphone:
print("Your microphone hole may be blocked, please clean this with a soft dry tooth brush, if this does not work then please retern the hand held device to its manufactures.")
sys.exit
elif battery:
print("If your battery is enlarged/swollen you have probbaly over charged it it is recomended that you buy a ned battery.")
sys.exit
elif speakers:
print("The speaker on most phone is located on the side or back or the device if this is blocked then please attemt to clean this with a dry, soft toothbrush, if this does not work please contact the product manurfacture.")
sys.exit
elif charger:
print("If you have not tryed buying a new charger then try that. If a new charger does not work, please send your mobile device to the product manurfacture.")
sys.exit
else:
print("please write your problem again, attempt to use keywords that relate to your problem.")
sys.exit
If someone could tell me how to correct this or correct this themselves it would be much appreciated.
you are not calling the function lower in line 3. In order to call it, you have to write 2 parenthesis after it. Thus, correct that line as follows:
problem = input("What is wrong with your mobile device?").lower()
The problem is actually on line 3. According to this article, Python 2 uses raw_input to get input, while Python 3 uses input. It looks like your code is expecting a Python 3 environment, but your environment is actually Python 2.
You can replace your call to input with a call to raw_input if you are, indeed, running in a Python 2 environment.
In addition, you must use parentheses after the call to lower so that the method actually gets called.
Python 2
problem = raw_input("What is wrong with your mobile device?").lower()
Python 3
problem = input("What is wrong with your mobile device?").lower()
I am working on some code for my game and I am having an issue. I apologize in advance if this is hard to understand. The first section works fine. There is a large amount of code so I pasted it into codepad.org for easier sharing. Here's the link; http://codepad.org/kT8szBb2
Lines 108 and 142 are supposed to work together. I've tried different things like adding in this:
if True:
to try and reposition the indent level but for whatever reason it doesn't seem to work. Any suggestions work; I'm willing to try anything even if it means re-writing the entire segment. Thanks in advance.
Okay, I think I've found the issue. You don't quite understand how indentation works. You have code that looks like this:
if a:
if b:
if c:
A()
else:
B()
else:
C()
This isn't how Python works. Python works with the following structure:
if a:
A()
elif b:
B()
elif c:
C()
I'd really like to know where that mistake in understanding came from, because this is some extremely messy code.
I took the liberty of refactoring your code to be sane.
def weaponsel():
swep = None
#again, I'm not really sure where this is coming from or what you're doing with it
#so it's hard to say if you should be saving the contents of swep before you run
#the function, possibly to return if you select /return/ at the first prompt?
while swep is None:
print "What weapon would you like to use?"
if weapondict["s1"] == None:
print "Error #1: No weapons in the backpack. Contact me (Karatepig) at /hashed out for security/ and make me aware of this error."
print "I can return you to the beginning of this checkpoint or I can end the game. Type /return/ to return or /end/ to end."
er1=raw_input()
if er1.lower() == "end":
import sys
sys.exit()
elif er1.lower() == "return":
return None
else:
print "Sorry, I don't understand."
er1d()
for weapon in ['s1','s2','s3','s4','s5','s6','s7','s8']:
if weapondict[weapon]:
print("The weapon {} is available".format(weapondict[weapon]))
# as a side note, this can probably also be:
## for weapon in weapondict.values():
## print("The weapon {} is available".format(weapon))
# but that depends on what weapondict looks like!
# It should be easy to expand to "types" of weapons, as well
# using something e.g.
## weapondict = {"Rusty Sword":Sword(dmg=3), "Sharpened Spear":Spear(dmg=7)}
# and testing for type(Sword) or type(Spear) based on player class or etc.
# but you'd need to build classes for this to work, e.g.
## class Weapon(object):
## def __init__(self,dmg=1):
## self.dmg = dmg
##
## class Sword(Weapon):
## self.type = "Sword"
## self.dmgType = "Slashing"
##
## class Spear(Weapon):
## self.type = "Spear"
## self.dmgType = "Thrusting"
# then you can have slashing do more damage to lightly armored targets and
# thrusting do more damage to heavily armored targets and etc. Even writing
# methods to attack characters based on their equipped weapons. This is a
# PRIME example of where OOP will get you big results fast!
weapon=raw_input()
if weapon.lower() not in weapondict.values():
print "Sorry, I don't understand that.\n\n"
continue
print("You have selected the {}".format(weapon))
swepd1 = raw_input("Is that what you want? ")
if swepd1.lower() in ("y","yes"): swep = weapon
If you have any questions, don't hesitate to ask. I haven't actually tested this, so syntax errors may abound. I'm fairly certain it works as intended, however. As a side note -- where does weapondict come from? It's not in your code anywhere and it's likely that this function can't see it (unless you defined it earlier as global weapondict.)
There is really no need for all those if's. You should absolutely be using a for loop.
weapons = { 1:'sword', 2:'mace', 3:'bow'}
for wep in weapons:
print('the {} is available'.format(weapons[wep]))
outputs:
the sword is available
the mace is available
the bow is available