Coding

What is the difference between a list and a dictionary?

Both store collections of values, but they organise them differently. A list keeps items in order and you find them by their position. A dictionary stores pairs of a key and a value, and you find a value by using its key.

Comparison (in Python-style terms): 1) A list is like a shopping list: ["milk", "eggs", "bread"]. The first item is at position 0, the second at position 1, and so on. 2) A dictionary is like a phone book: {"Sara": "555-0101", "Omar": "555-0102"}. You look up "Sara" to find her number. 3) Use a list when order matters or you have many similar items. 4) Use a dictionary when you want to look things up by a name or ID. 5) Keys in a dictionary are usually unique, but values can repeat.

Many languages call dictionaries other names, such as maps, hash maps or objects.

Which would you use to store the names and ages of your classmates, and why?

How can I debug my code when I do not know what is wrong?

Debugging is a skill you can learn, and most professional programmers do it every day. The aim is to narrow down where the problem is, one step at a time.

A method to try: 1) Read the error message carefully. It often names the file and line number. 2) Reproduce the problem so you can make it happen every time. 3) Check what you expect against what actually happens, using print statements or a debugger to see the values of your variables. 4) Make the problem smaller. Comment out or remove parts of the code until the bug disappears, then add them back. 5) Change one thing at a time and test again. 6) Explain the problem out loud, step by step, even to a rubber duck. This often reveals the mistake.

If you are still stuck, search the exact error message or ask for help with a short example that shows the problem.

What is the most confusing bug you have had to fix?

What is a function and why should I use one?

A function is a named block of code that does one job. You can run it whenever you need it by calling its name, and you can give it inputs (called parameters or arguments) and get a result back.

Why functions help: 1) They avoid repetition. Write the code once and reuse it. 2) They make code easier to read, because a good name like calculate_total explains what happens. 3) They make bugs easier to find, because you can test one small piece at a time. 4) They make changes easier. If the rule changes, you fix it in one place.

A practical test: if you copy and paste the same lines more than twice, consider making a function. Aim for each function to do one thing.

What was the first function you wrote?

How should a complete beginner start learning to code?

You do not need a special talent to start. What matters most is picking one language, practising a little regularly, and building small things.

A simple path: 1) Pick one beginner-friendly language such as Python or JavaScript, and stay with it for a few months. 2) Learn the basics first: variables, conditions (if/else), loops and functions. 3) Write code every day, even for 20 minutes, rather than only reading or watching. 4) Build tiny projects, such as a number-guessing game or a to-do list. 5) When something breaks, read the error message and search for it. This is a normal part of coding. 6) Look at other people's code and ask for feedback.

Do not try to learn everything at once. Finish small projects, then move to bigger ones.

Which language are you thinking of starting with, and why?

What is the difference between a variable and a constant?

A variable is a named place in memory that holds a value, and the value can change while the program runs. A constant also has a name and a value, but the value is not supposed to change after it is set.

Examples: 1) A variable: a score in a game. It starts at 0 and goes up as the player earns points. 2) A constant: a value like the number of days in a week, or a tax rate your program uses everywhere. 3) Using a constant gives the value a meaningful name and means you only need to change it in one place if it ever changes. 4) Some languages enforce constants with a keyword such as const or final. Others, such as Python, rely on a naming convention, usually capital letters like TAX_RATE.

A good habit is to use names that say what the value is, such as total_price, not x.

Can you think of a value in your own project that should be a constant?

Explain the key differences between procedural programmin...

This question aims to assess the understanding of two fundamental programming paradigms: procedural programming and object-oriented programming (OOP).

Category