Learn to Code with Python: A Course for Non-Coders

Too many courses out there but none of them click to you? Do they seem to cover too much material at once that it becomes hard to remember?

print('Hello world!')

That's all you need to print a message in Python.

This course is intended for people who are new to programming and want to learn Python in a simple and easy-to-understand manner.

It's important to note that as a beginner, you don't need to know every single function or keyword right away. Instead, you can learn them as you go along and tackle tasks that require their use, which will help you understand them better in the long run.

To get the most out of this course, I suggest dedicating 30 minutes to an hour every day to work through each section and complete the associated tasks. This will help you remember the concepts and challenge yourself.

Brief Python introduction and scope:

Getting started

Before we get our hands on the code, it's important we setup the development environment.

  • First, visit the official Python website at python.org/downloads and grab the latest package for your OS.

  • Once the installation is complete, you will have access to the Python IDE and launcher.

  • For a user-friendly and widely-used development environment, I recommend using Visual Studio Code (VSCode).

  • Download the latest version from https://code.visualstudio.com/download and install it on your system.

  • Install the checked extensions once VSCode has been set up:

Screenshot 2022-07-01 at 2.12.28 PM.png

Now we are ready to move on to the first step!

Note: Although some may be tempted to copy and paste code snippets from here, I highly recommend typing the code yourself to truly understand the concepts.

"Hello world!"

  1. Create a file with .py extension and open it in VSCode. It should look like this:

Screenshot 2022-07-01 at 2.24.24 PM.png

  1. Write the hello world code from above and execute it:

Screenshot 2022-07-01 at 2.28.51 PM.png

Variables in Python

In Python, variables are used to store values. To declare a variable, you need to give it a name and assign a value to it using the assignment operator (=). For example:

number = 147 # Declare an integer value
print(number) # Prints "147"

isTrue = True # Declare a boolean value
print(isTrue) # Prints "True" 

floatValue = 147.0 # Declare a float value
print(floatValue) # Prints "147.0"

myName = 'Rohan' # Declare a string
print(myName) # Prints "Rohan"

You can also assign multiple variables at once:

x, y, z = 5, 10, 15

Variables in Strings

In Python, you can use variables within strings by placing them inside curly braces {}. For example:

name = "Rohan"
print(f"Hello, {name}")

will output "Hello, Rohan"

Operators in Python

Python supports various operators such as arithmetic, comparison, logical, and bitwise operators. These operators allow you to perform various operations on variables and values. For example:

x = 5
y = 3
print(x + y) # 8 - Addition
print(x > y) # True - Comparision
print(x * y) # 15 - Multiplicaiton
print(x / y) # 1.66666 - Floating point division
print(x % y) # 2 - Modulus
print(x // y) # 1 - Floor Division
print(x ** y) # 125 - Exponentiation

Boolean and Conditions

A boolean value is either True or False. In Python, you can assign a boolean value to a variable or use it in conditions. For example:

feeling_hungry = True
if feeling_hungry:  #if variable has boolean value true
    print('feeling super hungry right now')
else:   #if boolean value is false then execute the following
    print('I don\'t feel hungry right now')

User Input

You can take input from a user and store the value in a variable with input() method. By default, the variable is stored as a string. For example:

name = input("Enter your name: ") # Store the input as string
age = int(input("Enter your age: ")) # Store the input as integer

Declaring a Dictionary

In Python, a dictionary is a collection of key-value pairs. You can initialize a dictionary using curly braces {}. For example:

person = {'name': 'Rohan', 'age': 30}
print(person['name']) #Rohan

Modifying values in a Dictionary

You can insert or update items in an existing dictionary using the update() method. It takes two arguments, the key which is to be added or updated and the value to be inserted. For example:

person.update({'age': 25, 'skill':'Python'})
print(person) # {'name': 'Rohan', 'age': 25, 'skill': 'Python'}

You can delete items in an existing dictionary using the del() method. It takes a single argument of dictionary[key]. For example:

print(person) # {'name': 'Rohan', 'age': 25}

Declare an Array / List

In Python, a list is a collection of items stored at contiguous memory locations. You can initialize a list using square brackets []. For example:

numbers = [1, 2, 3, 4]
print(numbers) # [1, 2, 3, 4]
print(numbers[0]) # 1 - This is printing item at 0 index in the list

Modifying values in a List

You can modify values in an existing list using the append(), insert() and del() methods. For example:

print(numbers) # [1, 2, 3, 4, 5]

numbers.insert(0, 0) # insert(index, value)
print(numbers) #[0, 1, 2, 3, 4, 5]

del(numbers[5]) # Delete item at index 5
print(numbers) # [0, 1, 2, 3, 4]

For Loop in Python

A for loop in Python allows you to iterate over a sequence (e.g. list, dictionary, string) and execute a block of code for each item. For example:

fruits = ["apple", "banana", "cherry"]
for x in fruits:

Random Number Generation

Python has a built-in module called random which allows you to generate random numbers. For example:

import random

Fortune Wish Teller - Mini Project

A simple mini project to create a fortune teller that will give a random fortune when run. For example:

import random
fortunes = ["You will have a great day!", "Things will go well for you today.", "Watch out for unexpected surprises."]

Small projects for practice:

Create a program to -

  • Ask user their age and print if they are eligible to vote.

  • Check if a given number is Prime or not.

  • Take a number input and print odd numbers till the given number.

  • Take a number input and print the sum of even numbers up to the given number.

  • Swap values of two variables.

Github Repo:


Thanks for your time!

Thank you for reading and considering this course. I hope it has been helpful in your journey to learning Python. Remember to take it one step at a time and don't be afraid to ask questions or seek help. Programming is a continuous learning process, so keep pushing yourself to learn new things and improve. Wishing you all the best in your programming journey!

- Rohan.