Topic outline

  • You can ask for help with the weekly Exercises either in the Exercise Sessions or in the course's official Slack workspace.

    Asking for help with a well-defined question

    "My program does not work, please help." This is a very general statement, and it does not make for a good question. Questions like this one take a lot of time for the answerer to try to figure out what is happening. 

    There can be any number of reasons a program does not work. For example, it does not compile, it throws an error, or it does not do the right calculations. In order for us to help you efficiently, YOU need to give us a more detailed description of the problem at hand. 

    Use the following structure for your question:

    1. Start with the error. What kind of error is it? Try to be as precise as possible about the error. When does the error occur? Which input works, which input does not work? 
    2. Describe, why you think the error occurs, or in which part of your code the error is.
    3. Describe what you have tried so far to solve the error.
    Examples of well-defined questions


    Example 1

    1. When I try to run my program main.py it does not run and I get the following error: 

    " File "C:/Users/me/pythonError/main.py", line 10  
        age := int(input("Enter your age\n"))
            ^
    SyntaxError: invalid syntax.

    2. I think that the syntax I am using on line 10 is not right.

    3. I tried to first assign age to zero, but the same error kept popping up.


    Example 2

    1. When I try to run my program main.py it starts running and asks for my input. After the input it throws the following error:

    Traceback (most recent call last):
    File "C:/Users/me/pythonError/main.py", line 42, in <module>
      ageCalculation(a)
    File "C:/Users/me/pythonError/main.py", line 9, in ageCalculation
      print(a)
    NameError: name 'a' is not defined

    2. I think the error is after the input handling (line 3-7) and before any calculations (line 10-21). 

    3. I tried to print a message to myself on line 8 and the message was printed, so I am pretty convinced everything works until line 8. I tried with the following inputs: 1998, 2020 and 1730,1798, and 2010,2012 but the error occurred for all the inputs in the same way.


    Example 3

    1: When I calculate the age of a person with a given year of birth for a given year it gives the wrong result. For example, for the input (1999, 2010), it outputs 10 instead of 11 years.

    2: I think something in my calculation (math) is not working as it should. I think it happens between line 5 and line 15

    3. I tried different inputs. My program works correctly for the input (2012,2015), where I get the right answer of 3 years, but not for the input (1999, 2010), where the program calculates 10 instead of 11.