What's wrong with maths script?
Question: Sorry if this is a beginner mistake but... I'm a beginner. Here's the script:

    
    
    num1 = input("Num1:");
    num2 = input("Num2:");
    
    try:
      val = int(num1)
    except ValueError:
       print("ERROR : Num1 is not a number!")
    
       val2 = inf(num2)
       except ValueError:
         print("ERROR : Num2 is not a number!")
    print("Maths");
    print(num1 + num2);
    

What the script is meant to do is add the two numbers and if they typed in
something which isn't a number it says it's not a number. I keep getting
errors but I don't know why. NOTE: this is Python.

This is the error I got:

>
>     File "<string>", line 10
>     except ValueError:
>     ^ SyntaxError: invalid syntax
>  


Answer: programming is all about breaking a (bigger) problem into smaller problems

the first smaller problem you have is to get integer input. a useful way to do
this is abstracting the problem out

    
    
    def get_integer(prompt=""):
        while True:
             try:
                return int(raw_input(prompt))
             except:
                print "Invalid input. please try again"
    

now you can simply call this method when you want an integer from the user

    
    
    n1 = get_integer("Enter the first integer:")
    n2 = get_integer("Enter The second integer:")
    

next you must determine how to add those

    
    
    import operator
    def get_operation():
        my_operators = {"+":operator.add,"-":operator.sub}
        while True:
              try:
                  return my_operators[raw_input("Enter a + or -:")]
              except KeyError:
                  print "Invalid input!"
    

now you can combine the 2 easily

    
    
     n1 = get_integer("Enter the first integer:")
     n2 = get_integer("Enter The second integer:")
     print get_operation()(n1,n2)
    

you should see something like

    
    
    >>> n1 = get_integer("Enter the first integer:")
    Enter the first integer:7
    >>> n2 = get_integer("Enter The second integer:")
    Enter The second integer:8
    >>> print get_operation()(n1,n2)
    Enter a + or -:+
    15
    

