dimanche 3 novembre 2019

I am not very experienced, how do I shorten this?

Okay, So I'm a beginner to python, and while I have no internet I decided to make a simple console game using input, if, else, elseif, etc. but It's getting hard to understand, and I don't really know how to clean it up. If anyone can help me that would be much appreciated! (Currently using python 3.3.2), and just from my code preview alone, you can see part of my issue...

The pastebin link is below. (It's easier to view a pastebin than my post, so I decided to put it in a pastebin.) https://pastebin.com/0y017hNs

begin = input("Would you like to begin? (y/n) ") #Start of the game, prompting them to type y or n to begin.

if begin.lower().strip() == "y": #checking for if they want to begin (y)

    lrDir = input("You reach a sign that says ""Go left or right"" which way to you go? ").lower().strip()
    if lrDir == "left":
        Money = 100 #Creating the variable Money
        ra = input("You encounter a theif, would you like to run or attack them? You have a sword (not able to weild effectively yet), a book, a torch, and $" + str(Money) + " available in your inventory. (attack or run) ") #Making "answer" equal Attack or Run.

        if ra == "attack": #checking for if they chose attack
            Money = Money - 30 #Subtracting 30 from the variable Money.
            print("You have a sword but not yet able to use it, You try to attack with your fists but he's stronger than you. you have been robbed of $30. Your new balance is: $" + str(Money)) #str(Money) is turning money into a string, so that it can be printed.
            e = input("You are close to a village, would you like to enter it? (y/n) ")
        if e == "y":
            print("You have been taken in as part of the village people. You are currently trusted. Try not  to mess it up.")
            print("To be continued")

        elif e == "n":
            er = input("It's starting to get dark, so you will want to find shelter. There's a axe laying on the ground, could be a potential murder weapon. Would you like to pick it up? y/n ")

Aucun commentaire:

Enregistrer un commentaire