Python Classroom notes 27/Aug/2024

Project Euler Problem 2

1. Hello flora
2. a = 1
3. b = 2
4. result = 2
5. c = a + b
6. if c%2 == 0
    6.1 result = result + c
7 a = b
8. b = c
9. if a + b < 4 million
    9.1. go to step 5
10. print result

Python

  • Python has different compilers available out of which CPython is most widely used.
  • Python has important principles embedded
  • Zen of Python (PEP-20) Refer Here
  • Python Style Guide Refer Here
  • Python is developed by opensource communitiy Refer Here
  • Python creates a PEP (Python Enhancement Proposal) for all the features
  • Ensure Pylint extension is installed

Hello World python program

  • Create a file called as helloworld.py
"""
This is my first program
"""

print("Welcome to python")

  • Executing the program python helloworld.py
  • Executing the program from visual studio code
    • Navigate to Run => Start without Debugging
  • Open Command pallete in visual studio code ctrl+ shift + p and Type Terminal: Focus Terminal

Basic Data Types in Python

  • Refer Here for article of Datatypes in Python
  • Also refer w3schools, geekforgeeks, Programiz
  • REPL (Read evaluate Print loop) can be opened by typing python in shell
  • Note: We have interesting functions
    • type
    • print

Naming conventions

  • Pascal Casing:
    • myworld => MyWorld
    • account => Account
    • myfirstaccount => MyFirstAccount
  • Camel casing:
    • myworld => myWorld
    • account => account
    • myfirstaccount => myFirstAccount
  • Captial casing
    • myworld => MYWORLD
    • account => ACCOUNT
    • myfirstaccount => MYFIRSTACCOUNT
  • Snake casing
    • myworld => my_world
    • account => account
    • myfirstaccount => my_first_account
  • CAPITAL SNAKE Casing
    • myworld => MY_WORLD
    • account => ACCOUNT
    • myfirstaccount => MY_FIRST_ACCOUNT

Variables in Python

  • variable is a name given to some value in python
  • variable naming conventions
    • use snake casing for variables
    • use capital snake casing for constants
  • Python doesnot have constants but if the value does not change use capital snake casing

Operators in Python

Sample Programs on Operators

Exercises

  • Calculate loan emi
  • Temparature conversion from degree to farnheit
  • Number of seconds so far (hours = 0 minutes = 10 seconds = 11)
  • Kilometres to miles
  • Kilograms to pounds
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%