No frills here but just practice. I can keep showing you all the tools and features a programming language has, but the true goal of everything is to teach you how to think.

The reality of being a programmer is learning the thinking part more so thanany of the tools we use in expressing ourselves as programmers. Good programmers, even with terrible programming languages that barely have any features are able to create great things not because of the toolset they have with them but the manner of thinking.

So far I showed you some of the core aspects of the programming language - variables, conditionals, loops, primitive data types but that was to give you a very basic understanding of the building blocks that make up every program. There are a couple of others too that I will teach but I’ll slow my pace here to give you more focus on problem solving with these and these will actually build up your confidence.

Google around but only to get unstuck or look up some feature, not the answer to these problems which I’m sure plenty exist. These will be simple and in a variety of types but I want to tune your thinking with loops.

Even if you think they’re ‘simple’ keep doing them, it’s being really good at the simple that unlocks the later parts.

You can take many sessions for this, or one, it doesn’t really matter so long as you are learning.

Printing numbers

  • Print numbers from 0 to 9

  • Now recall that you can use range(start_number, end_number), print all numbers between 20 and 40.

  • Print the first 15 odd numbers like
     1
     3
     5
     .
     .
     .
     27
     29
    
  • Print the numbers 9 to 0 in reverse order. Time to google around and figure out (and in general a good practice to pick up)

Printing patterns

Now the American education system doesn’t have much of these but these are a staple of Indian schools.

Also recall that multiplying strings can repeat them

>>> "#"*3
'###'
>>> "@"*10
'@@@@@@@@@@'
  • Print n lines from user input (n = 5 in this example)
    @@@@@
    @@@@@
    @@@@@
    @@@@@
    @@@@@
    
  • Print a pyramid (n = 4 here)
    $
    $$
    $$$
    $$$$
    $$$
    $$
    $
    

Sums and products

  • Remember that program where you kept on going till the user entered an empty line. Similar to that write a program that takes a new number on every line and adds it up. It will stop adding when you enter a zero.

  • The classic factorial program. Take a number input from the user for a number and calculate it’s factorial. Remember that factorial is just the product of all the numbers from 1 upto the number. This is a concept that comes a lot in computer science, statistics and mathematics and luckily you can do it with quite a simple for loop.
    5! = 1 * 2 * 3 * 4 * 5 = 120 
    3! = 1 * 2 * 3
    1! = 1
    0! = 1 (Yes you have to be able to hit this case as well)
    
  • Write a program to sum all it’s digits. 123 becomes 6, 111 becomes 3, 100009 becomes 10 This is a pretty interesting one to do and I suggest breaking it down in parts (how to extract each digit, how to make it work for all sorts of numbers etc.