Computer Science, asked by shiv7695, 10 months ago

write a python code for chest​

Answers

Answered by yashgandhi74
0

Move your startup/init code into a main routine, and replace it with the more usual Python idiom:

if __name__ == '__main__':

main()

As a pet peeve, get rid of the delay timers. I don't think they add any value, and they do make it irritating when debugging.

Move your data away from your code. For example, you have a bunch of literal text in your showInstructions function. Instead, create a list of tuples:

INSTRUCTIONS = [ # (title, text)

("Instructions", """You are a treasure hunter, your goal is to collect at least

100 gold by the end of the game from treasure chests randomly ..."""),

# ... etc ...

]

Then use the tuples in a simple loop inside showInstructions:

def showInstructions():

"""Hide main window, then show a series of message boxes with instructions in them."""

window.withdraw()

for title, text in INSTRUCTIONS:

messageBox(title, text)

Also, since your message boxes always end with "Press enter to continue..." go ahead and define a messageBox function that appends that text.

def messageBox(title, text):

message = text.rstrip() + '\n\nPress enter to continue...'

messagebox.showinfo(title, message)

Decide how you want to handle input, and write a function to do that. Checking a Y/N response for a 'y' and an 'n' is annoying. Users prefer there to be a default behavior that requires only one answer. For example, if the default is N, then the user can type 'Y' or just hit enter, defaulting to N. This will reduce the amount of code you have to write, as well.

Writing a function for this should be easy and obvious. You can return a boolean true for yes, false for no, and use that inside an if statement:

if ask_yorn("Are you sure you with to play this game?"):

print("Okay lets continue then!")

print("")

print("")

print("""~~~~~~~~~~MENU~~~~~~~~~~""")

# ...

else:

quit("Thank you for playing!")

A same suggestion applies to numeric text entry for selecting from a menu. Write a function that takes a maximum value, a prompt, and keeps looping until a valid input is found. Call it get_number(3, "> "). Let the return value be the integer result.

Collapse your various xxx_easy/med/hard functions into code as much as you can. Your only change seems to be the board size, so why not just create a size variable, or use the len(board) directly to know how many rows/columns there are?

Write a function to handle getting a board command, checking it against the valid list of commands, and returning a valid result. It should just loop until something valid happens, either up, down, etc or an exit.

Finally, stop using current[0] and current[1]. You are storing values into the list, then unpacking the elements of the list each time. You should consider some of these possibilities:

Declare global position (instead of current) and stop passing arguments.

Create a namedtuple and use current.x, current.y.

Create a tuple and pass it directly.

Create global X and global Y and pass them directly

Answered by usjadhav2001
0

Answer:

ik

thank you

Explanation:

It is so because when the volume of chest cavity increases the foul air that is carbon dioxide goes out from our body through the lungs but when it decreases or expands the air that is Oxygen comes in our body through lungs

Similar questions