Day 2 - Basic Python Constructs

Much of the python code that I wrote today were a couple of the chapter examples in the Udemy Ultimate Python Programming Course. However, having discovered Pylint, I went back and coded up the examples in the chapters that I covered (6 and 7) and made them pass pylint tests.

The most valuable exercise was the ‘python calculator’:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" - udemy chapter 7, exercise 2 """

OP1 = 0.0
OP2 = 0.0
OP = ''

while OP1 != 'q':
    print 'Enter first number (q to quit): '
    OP1 = raw_input()
    if OP1 == 'q':
    OP1 = float(OP1)
    print 'Enter second number: '
    OP2 = float(raw_input())
    print 'Enter an operation (+,-,*,/): '
    OP = raw_input()
    if OP == '+':
        print OP1 + OP2
    elif OP == '-':
        print OP1 - OP2
    elif OP == '*':
        print OP1 * OP2
    elif OP == '/':
        print OP1 / OP2
        print 'Did not recognize operator.'

The example basically shows two of the basic programming constructs in Python, the while loop and the if-elif-else construct(s). However, when I ran this again Pylint to test the syntax there were a couple things that needed to be changed:

I think that this exercise was more valuable in the sense of learning pylint, rather than the basic constructs of the language- those I already know. Pylint is explicit on how your syntax should look. This one pass the pylint test with a 10/10. Perfect.

Jason T Clark

Jason T Clark

Father. Musician. Gamer. Coder.

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin