#Why is this invalid syntax?

56 messages · Page 1 of 1 (latest)

spice etherBOT
#

@median basin

vampbalism Successfully Uploaded Some Code

This is for a magic gun generator for a very homebrew dnd campaign, just for refrence about what it's supposed to do.

Uploaded these files to a Gist
median basin
#
start = input("|||START:k|||")
while start == ("k"):
    answer = input("|||Press Enter x2||")
    if (answer== input()):
        guntopt = (random.choice(guntype))
        print ("-------------------------")
        print ("|GUN TYPE: " + guntopt)
        print ("|GUN SIZE:",(random.choice(gunsize)))
        if guntopt == ("redpowder"):
            print ("|SHOTS: " + (random.choice(rpshots))
            print ("|COOLDOWN:" + (random.randint(1,2) + "seconds")
        if guntopt == ("hybrid"):
            print ("|SHOTS: " + (random.choice(bsshots))
            print ("|COOLDOWN:" + (random.randint(1,4) + "seconds")
        if guntopt == ("bloodshot"):
            print ("|SHOTS: " + (random.choice(bsshots))
            print ("|COOLDOWN:" + (random.randint(1,2) + "seconds")
        if guntopt == ("rayspitter"):
            print ("|SHOTS: Ammoless)
            print ("|COOLDOWN:" + (random.randint(1,6) + "seconds")```

specifically this part
north nebula
#

One ( too much

river ginkgo
#

Have a look at the previous line above where the error is pointing to. Count the number of parenthesis you have

north nebula
#

Also you don't need the parentheses in the comparisons

median basin
#

same error, fixed all the parenthasies

river ginkgo
#

Do the same thing

median basin
potent token
#

The amount of brackets makes me think this is Lisp

north nebula
median basin
#

aahh

north nebula
#

Half the brackets on the screenshot are redundant

potent token
#

It's a programming language in which brackets are used a lot. Some of the brackets in your code are unnecessary

north nebula
river ginkgo
#

@median basin You should be pasting your code to share it. That way people can copy it and modify it to show you how many brackets can be reduced.

median basin
river ginkgo
#

True

#

I forgot mb

median basin
#

it's giving me a different error now

north nebula
#

The issue in line 46 is still there

#

Like I said

#

Just count your parentheses, should be the same amount of opening and closing ones

#

Also things might be clearer if you get rid of the ones you don't actually need

median basin
#

print ("|COOLDOWN:" + (random.randint(1,4)) + "seconds")

#

it says this is invalid syntax

north nebula
#

Yeah

#

Because the line before that is incorrect

#

Did you read the 3 messages in which I told you line 46 is the issue?

river ginkgo
#

You can't concatenate ints and str?

median basin
north nebula
#

3 opening, 2 closing

potent token
#

Did you not test your code while writing it? There are so many errors

#

Like I test my code after some progress. I run into fewer errors if I do that instead of writing the whole thing at once

north nebula
#

Gotta use le f-strings

#

Or str(some int value)

median basin
river ginkgo
# median basin

Concatenation is putting one thing next to another. The error is telling you that you can't put a string and an integer together. This is because they're two different data types and python doesn't know exactly how you want to handle the + between them

median basin
#

Ahh ok

river ginkgo
median basin
#

I'll just take out the "seconds" part

river ginkgo
#

Either using string formatting (f-strings) or convert the integer into a string (which will allow string to string concatenation)

potent token
#

or you can use vim motion

median basin
#

also I apologize for the repeated errors with the parenthasies, I have dyslexia and I have serious issues determining how many of one sort of symbol there are next to each other.

potent token
#

probably better to code in an IDE and install an extension for colorful brackets then

median basin
#

I'm on a chromebook, online-python is the best browser based one I know of.

north nebula
river ginkgo
#

Lmao fair enough

median basin
#

oh one more thing actually

#

how do I make it give me an intager as a string?

potent token
#

we told you twice how to do it...

median basin
potent token
#

yes