Python - Week 1 - Using for loop and range function

This is the first in the series of Python programs I have written.

Did some basic reading on Python to familiarize myself with Python syntax. Based on what I know so far I am using Python functions, for loop, range function, if statements, remainder operator and print method.

The problem I am trying to solve is borrowed from github:

Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5 between 2000 and 3200 (both included).

The numbers obtained should be printed in a comma-separated sequence on a single line.
There are some key takeaways from this program:

  1. When typing Python programs, be sure to start all your unnested statements in column 1 (that is, all the way to the left). If you don’t, Python may print a “SyntaxError” message, because blank space to the left of your code is taken to be indentation that groups nested statements.
  2. There are no type declarations in Python, the syntax of the expressions you run determines the types of objects you create and use.
  3. A variable is created when you assign it a value, may be assigned any type of object, and is replaced with its value when it shows up in an expression. It must also have been previously assigned by the time you use its value.
  4. Variable Names have no types, types live with objects assigned to names, not names. so if we say lb = 2000, 2000 is an object that has type integer. lb does not have a type.
  5. The == operator, tests whether the two referenced objects have the same values; this is the method almost always used for equality checks in Python.

Comments

Popular posts from this blog

Python - Week 8 - Dictionaries, Tuples, Sorting and Filtering

Python - Week 3 - Lists, Tuples, Slicing, Math Functions

Python - Week 5 - Comprehensions