Lecture: Hello World

Printing "Hello World" on the output console:

print('Hello world')


Lecture: Mathematical operators in Python


Addition:

100+20


Subtraction:

200-40


Multiplication:

45*67


Complex mathematical operations:

4*6*(28+5)


Division:

200/2


Floor division:

If we do not want to get a decimal value we could use // instead of /.

200//2


Divide by zero:

345/0

This will give a divide by zero error.


Mathematical operations with float:

12.0 * 4



Lecture: Complex mathematical operations


Modulus:

21%4


Modulus with float:

456.34%2


Clearing Python Shell:

On Windows:

import os
os.system('cls')


On Mac/Linux:

import os
os.system('clear')

Lecture: Strings in Python


Escaping a single quote: i.e a " ' ":

'He\\'s a good guy'

Output:

" He's a good guy "


Using single quotes to escape double quotes:

'This is the "only" way to go'


Escaping multiple double quotes:

"This is the \"only\" way to go"



Lecture: Accepting user input

input('Enter your name')


Lecture: String operations


To check the data type:

type(8)
type('8')


String operations

Concat:

"Hello" + " world"


Including space between two strings:

"Hello " +  "World"


Concatenating two numbers as a string:

"10" + "10"


Concatenating string & number as a string.

"Hello " + "5"


Concatenating string with a number

"Hello" + 5


Multiplying a string with a number

"Hello " * 4


Multiplying a string with another string

"Hello" * "Hi"



Lecture: Data types in Python


Integer:

print(10)
type(10)


Float or floating point numbers:

type(6.2)


A boolean type :

>>> True
True
>>> False
False
>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>


Complex numbers:

5+9j

Lecture: Variables in Python


Declaring a variable:

a = 200


Declaring another variable b:

b=20


Value of a variable can be changed at any instance:

a= 100
print(a)
a=200
print(a)


String variables:

name = "John"
type(name)


Float Variable:

a= 3.2
type(a)


Boolean Variable:

b= True
type(b)

Lecture: Accepting Input & Adding Numbers


a = int(input("Enter First Number"))
b = int(input("Enter second Number"))
print(a+b)


Lecture: Generating Username & Password Using Concatenation


firstname = input("Enter firstname: ")
lastname = input("Enter lastname: ")
username = firstname+lastname

email = firstname+lastname+"@gmail.com"
print("Username is: "+username)
print("Email is: "+email)


Lecture: Comparing User Strings


saved_password = "123admin123"
user_password = input("Enter password")
print(saved_password==user_password)


Lecture: Creating A Simple Interest Calculator


principal = int(input("Enter amount lent"))
years = float(input("Enter lending period in years"))
rate = float(input("Enter rate of interest"))

interest = principal * years * rate / 100
print("Simple interest calculated is"+ str(interest))


Lecture: F Strings In Python


principal = int(input("Enter amount lent"))
years = float(input("Enter lending period in years"))
rate = float(input("Enter rate of interest"))

interest = principal * years * rate / 100
print(f"Simple interest on the principal amount $ {principal} for a period of {years} years at the rate of {rate} is $ {interest}")


Lecture: Creating BMI Calculator


weight = float(input('Enter weight in kgs'))
height = float(input('Enter height in meters'))

bmi = weight/(height*height)
print('BMI is: '+str(bmi))