Sessions with Pradyun

Follow Python Installation Steps From Here:   Https://Learn.Swapnil.Pw/Python/Pythoninstallation/

print("HELLO")

# 1. INSTALLATION - getting your computer ready
# a. you can practice online at Google Colab (colab.reaserch.google.com)
# b. install all software on your machine -
## i. install Python : python.org and download the version of your choice
## ii. you can program on Python but its very easy to do
## iii. Another software to make it user friendly - IDE
## integrated development environment - you can practice
## eg Pycharm (jetbrains.com), VS Code , Notebooks like Jupyter, etc
print(‘Hello’,end=“\n”);print(“Good Morning”, end=“.     \n3.”);  # end has invisible new line
print(“Hope you are doing well”,end=“\n”);
print(‘Hello’,end=“\n”)
print(“Good Morning”, end=“.     \n3.”);  # end has invisible new line
print(“Hope you are doing well”,end=“\n”)
print("HELLO", end="\n")
print("Good Morning")
# variables - we variable to store data and use it again and again when we want it

var1 = 5
# single line comment
# integer means - numbers without decimal part- includes _ve , +ve & zero

# type() - it gives the data type of the variable
print(type(var1)) # integer - int

# basic data types in Python- integer, float, string, boolean & complex
# basic = single value
print(var1)
var1 = 5.0 #float
print(type(var1))

var1 = 5+2j
print(type(var1))
print(var1 * var1) # 25 -4 +20j
print(2j * 2j)

var1 = "7890"
print(type(var1)) # str -> string

var2 = '5.4t'
print(var2)
print(type(var2))

#bool -> boolean : True / False
var1 = True
var2 = False
print(type(var1))

### use these values/ variables
# Arithematic operations - input as numbers and output are also numbers
# + - * / // ** %(modulo)
var1 = 14
var2 = 5
print(f"{var1} + {var2} : ",var1 + var2)
print("{var1} + {var2} : ",var1 + var2)
print(f"var1 + var2 : ",var1 + var2)

print(f"{var1} - {var2} : ",var1 - var2)
print(f"{var1} * {var2} : ",var1 * var2)
print(f"{var1} / {var2} : ",var1 / var2)

print(f"{var1} // {var2} : ",var1 // var2) #integer division
print(f"{var1} % {var2} : ",var1 % var2) #remainder from division
print(f"{var1} ** {var2} : ",var1 ** var2) #power- var1 to the power var2
print(f"{var1} ** {var2} : ",var1 * var1* var1*var1*var1)
# round() - round it off to the nearest integer value
### round(5.1) = 5 , round(5.6) = 6
# floor() - rounds it off to the lowest integer value
### floor(5.1) = 5 , floor(5.6) = 5 => similar to integer division
# ceil() - rounds it off to the higher integer value
### ceil(5.1) = 6 , ceil(5.6) = 6
# types of variables (data types) - Basic data types - they can store only one value at a time
var1 = 5 # integer - int
var1 = 5.0 # float
var1 = 5j #complex
var1 = "5" #string - str
var1 = False #boolean - bool
# arithematic operators: + - * / // %(mod) ** (power)
# Comparison operators: numeric as input and output is bool
num1, num2 = 10,20
print(num1, num2)
# > >= <= < == !=
print("num1==10: ",num1==10) # is num1 equal to 10 ?
print("num1!=10: ",num1!=10) # is num1 not equal to 10?
print(num1 > num2)
print(num1 < num2)
print(num1 >= 10)
print(num1 <= num2)

# Logical operators
#input values and output values - are all boolean
#operations = and or not
print("not True: ",not True)
print("not False: ",not False)
# and -> both values have to be True for it to be True else its False
print(True and False)
#tell: I will do this work and that work
#actual: I did only this work
#did I meet my committment ? - NO
# or - both values have to be False to be False otherwise its always True
#tell: I will do this work or that work
#actual: I did both
print("OR = ", True or False)
num1,num2 = 10,20
print("==> ",num1==10 and num1!=10 or num1 > num2 and num1 < num2 or num1 >= 10 or num1 <= num2)
# True

radius = 4
pi = 3.14
area_of_circle = pi * radius**2
circumference = 2 * pi * radius
print("Area of a circle with radius",radius,"is",area_of_circle,"square unit and circumference is",circumference,"unit")
# f - string is for formatting
print(f"Area of a circle with radius {radius} is {area_of_circle} square unit and circumference is {circumference} unit")

# Assignment -
# 1. WAP to find area and perimeter for a square
# 2. WAP to find area and perimeter for a rectangle
# for both the programs, display output is complete message as we have done above with circle.

# to check given number is an odd or even ?
# 5 - odd, 6 - even
num1 = 5
if num1 % 2==0:
print("EVEN Number")
else:
print("ODD Number")
num=0
if num>0:
print(“Number is positive”)

if num>0:
print(“Number is positive”)
else:
print(“Number is not positive”)
num=11
if num>0:
print(“Number is positive”)
if num%2==0:
print(“Its even”)
else:
print(“Its odd”)
elif num<0:
print(“Number is negative”)
else:
print(“Neither positive nor negative”)

#WAP to check if a number is Odd or Even

#WAP to assign grade based on marks obtained
avg = 85
#avg>=85: A, 70-85: B, 60-70: C, 50 to 60: D, <50- E

#LOOPS are used to repeat multiple times
#FOR – when u know exactly how many times to repeat
# range(start(=),stop(<),increment(=)) = range(5,25,5): 5,10,15,20
for counter in range(5,25,5):
print(counter)

# range(start(=),stop(<)) = range(5,10) default increment = 1: 5,6,7,8,9
for counter in range(5,10):
print(counter)

# range(stop(<)) = range(4) DEFAULT start= 0,default increment = 1: 0,1,2,3
for counter in range(4):
print(counter)

#WHILE – till a condition is true
count = 10
while count<=15:
print(“Value = “,count)
count=count+1
for v in range(1,11):
for r in range(1,11):
print(f”{r:<2} * {v:<2} = {v*r:<2},end=” “)
print()

”’
*
* *
* * *
* * * *
* * * * *
”’
for i in range(5):
for j in range(4-i):
print(” “,end=“”)
for k in range(i+1):
print(“*”,end=” “)
print()

############# Assignment
”’
* * * * *
* * * *
* * *
* *
*
”’
#Guessing game: Computer v Human
import random
#guess = 25
guess = random.randint(1,100)
counter = 0
while True:
num = int(input(“Guess the number between 1 and 100: “))
if num<1 or num>100:
print(“Invalid guess, try again!”)
continue
counter+=1
if num==guess:
print(f”Congratulations! You got it right in {counter} attemmpts.”)
break #throw you out of the loop
elif num<guess:
print(“Incorrect, You’re guess is lower!”)
else:
print(“Incorrect, You’re guess is higher!”)

#Guessing game: Computer v Computer
import random
#guess = 25
guess = random.randint(1,100)
counter = 0
start,end=1,100
while True:
#num = int(input(“Guess the number between 1 and 100: “))
num = random.randint(start,end)
if num<1 or num>100:
print(“Invalid guess, try again!”)
continue
counter+=1
if num==guess:
print(f”Congratulations! You got it right in {counter} attemmpts.”)
break #throw you out of the loop
elif num<guess:
print(“Incorrect, You’re guess is lower!”)
start=num+1
else:
print(“Incorrect, You’re guess is higher!”)
end=num-1

###############
txt = “Hello”
# indexing
print(txt[0]) #counting in Python starts from zero
print(txt[4])
print(txt[-1])