Jump to content

Python code started to say bad syntax?!?

def main():

    action = input("Division, multiplication, addition, or subtraction? ")

    n1 = float(input("What is your first number? "))

    n2 = float(input("What is your second number? "))

    if action == "multiplication"

        print(multiplication(n1, n2))

    elif action == "division":

        print(division(n1, n2))  

    elif action == "addition":

        print (addition(n1, n2))

    elif action == "substraction":

        print (substraction(n1, n2))

                                                                                                                                              

def substraction(num1, num2):

    return num1-num2

                                                         

def addition(num1, num2):

    return num1+num2

                                                                                                                                            

def division(num1, num2):

    return num1/num2

 

def multiplication(num1, num2):

    return num1*num2

    

main()

Excuse the really bad colouring on the letters.

 

For some reason this calculator bit of code i made started giving me syntax error on that bigger than the rest red print and i dont know why... It worked fine when i run the code a few hours ago and havent tampered with it yet...

 

Here is a print screen to show what happens when i press F5 to run it

 

using python 3.4

 

1080p image

 

bNsStNm.png

My PC:

Spoiler

MOBO: MSI B450 Tomahawk Max, CPU: AMD Ryzen 5 3600, Cooler: BeQuiet! Dark Rock 3, GPU: Gigabyte GTX 1050ti D5 4G, Ram: 16GB (2x8) HyperX Fury DDR4, Case: NZXT S340, Psu: Be Quiet! Pure Power 11 600W , HDD's: WD 1TB Caviar Blue, WD 256GB Scorpio Blue, WD 2TB Caviar Blue  SSD: Sandisk SSD PLUS 240Gb

Link to comment
https://linustechtips.com/topic/300104-python-code-started-to-say-bad-syntax/
Share on other sites

Link to post
Share on other sites

You forgot the colon on the end of the if statement in the line above the red print.

Well, i put it in and then after saving it and running it again, it puts syntax error and highlights the colon :/

 

mbxP77s.png

My PC:

Spoiler

MOBO: MSI B450 Tomahawk Max, CPU: AMD Ryzen 5 3600, Cooler: BeQuiet! Dark Rock 3, GPU: Gigabyte GTX 1050ti D5 4G, Ram: 16GB (2x8) HyperX Fury DDR4, Case: NZXT S340, Psu: Be Quiet! Pure Power 11 600W , HDD's: WD 1TB Caviar Blue, WD 256GB Scorpio Blue, WD 2TB Caviar Blue  SSD: Sandisk SSD PLUS 240Gb

Link to post
Share on other sites

Well, i put it in and then after saving it and running it again, it puts syntax error and highlights the colon :/

 

mbxP77s.png

Oh, there's a missing ")" at the end of the n2 input too.

Link to post
Share on other sites

-snip-

It worked, a bit of an akward highlight considering the source of the problem was above it :P

 

Thanks, rookie mistakes

My PC:

Spoiler

MOBO: MSI B450 Tomahawk Max, CPU: AMD Ryzen 5 3600, Cooler: BeQuiet! Dark Rock 3, GPU: Gigabyte GTX 1050ti D5 4G, Ram: 16GB (2x8) HyperX Fury DDR4, Case: NZXT S340, Psu: Be Quiet! Pure Power 11 600W , HDD's: WD 1TB Caviar Blue, WD 256GB Scorpio Blue, WD 2TB Caviar Blue  SSD: Sandisk SSD PLUS 240Gb

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×