Python Sample Code contains all the examples explained while teaching Python. Sample Code is organized as per the order of the episodes. Each sample code includes complete source code the example from basic print statements to Complex Numpy examples.

But again it’s a request to view the sample code only if you have tried 10 times while watching Python Online Session.

If you enrolled for the course you can refer to the episode number or name of the session to get the source code. If you have not enrolled for the Python Online Curse Please Click and enroll today.

**For enrolled students, we also provide online support along with additional Practice Series.**

If you think this sample code is not enough please refer to our practice series available 100% free on YouTube. Here is the link to Python Practice Series with many new examples. We will add new examples of Python Practice each and every Saturday.

## Does Sample Python Code Include all the exercise ?

Nope. The answer is no. It includes the example only explain in the source code. More example of the practice is available here (Python Exercise List).

## Episode 3 to Episode 5 Python Sample Code

All the sample Codes from Episode 3 to 5. Since the First and Second episodes of Python don’t have any source code explanation we are skipping that.

### Episode 3 – Sample Code

Simple Program to Print Hello

print("Hello")

Output in 3 Different Lines

print("C") print("C++") print("C#")

Understand the use of \n escape character in Python

print("C\nC++\nC#")

Program to understand the use of \n and \t escape character in Python

print("C\n\tC++\n\t\tC#")

### Episode 4

Display int Variable and it’s a data type in python

x = 250 print(x) print(type(x))

Float variable Assignment and Display its type using “type” function

y = 2.0 print(y) print(type(y))

Display string variables and their types in python

x = "python programming" print(x) print(type(x))

### Episode 5

Understand the different variables and data types in python. Program to store cricket detail in different variables

player ="Sachin Tendulkar" country = "India" matches= 200 runs = 16000 batting_average = 44.83 print("Name of Player:", player) print("Player from:",country) print("Matches Played:",matches) print("Runs scored:",runs) print("Batting average:",batting_average)

## Episode 6 to Episode 10 Python Sample Code

### Episode 6

country = "India" population = 130 print ("population of", country, "is", population, "crores")

typecasting or Type Conversion:

country = "India" population = 130 print ("population of", country, "is", population, "crores") print ("population of " + country + " is " + str(population)+ " crores")

### Episode 7

country = "India" population = 130 print ("population of %s is %d crores"%(country, population))

Print up to 2 Decimal Points:

name = "Rajesh" age = 45 height = 5.6 print ("Mr. %s is %d year old. His height is %f feet."%(name,age,height))

Rounding Off Logic:

name = "Rajesh" age = 45 height = 5.6 print ("Mr. %s is %d year old. His height is %.0f feet."%(name,age,height))

### Episode 8

addition of two numbers:

x = 10 y = 20 z = x + y print(z)

how to use input function in python

name = input("Please enter your name") print ("Hello!", name)

book_name = input("Please enter the name of your favorite book") author = input("Please enter the Author name") print ("Your favorite book is:", book_name ) print("It is Written by Author:", author)

### Episode 9

# 1st program without int

x = input("Enter first number") y = input("Enter second number") z = x + y print("Addition of ", x, " and ", y, " is ", z)

#2nd program with int

x = input("Enter first number") y = input("Enter second number") z = int(x) + int(y) print("Addition of ", x, " and ", y, " is ", z)

#3rd program with float

x = input("Enter first number") y = input("Enter second number") z = float(x) + float(y) print("Addition of ", x, " and ", y, " is ", z)

# 4th program with input as float

x = float(input("Enter first number")) y = float(input("Enter second number")) z = x + y print("Addition of ", x, " and ", y, " is ", z)

### Episode 10

# 1st program with division

balls = 11 friends = 4 ball_distributed = balls / friends print("Each friend will get ", ball_distributed)

# 2nd program quotient with floor division

balls = 11 friends = 4 ball_distributed = balls // friends print("Each friend will get ", ball_distributed)

# 3rd program quotient with floor division and the remainder with modulus

balls = 11 friends = 4 ball_distributed = balls // friends ball_remaining = balls % friends print("Each friend will get ", ball_distributed) print("Remaining Balls ", ball_remaining)

#4th program exponential operator

x = 4 ** 3 print("value of x is", x)

## Episode 11 to Episode 15 Python Sample Code

All the sample Code from Episode 11 to 15.

### Episode 11

#1st program += operator

x = 5 x += 3 print("x =", x)

#2nd program -= operator

x = 5 x -= 3 print("x =", x)

#3rd program of metal strip divide into 5 meter strips then from remaining again divide it into 3 meter and print wastage

strip_length = int(input("Enter length of the metal strip : ")) p5 = strip_length // 5 strip_length %= 5 p3 = strip_length // 3 strip_length %= 3 print("number of 5 meter length pieces are :", p5) print("number of 3 meter length pieces are :", p3) print("The wastage is ", strip_length)

### Episode 12

#1st program

#defining the boiling and freezing temp in Celsius boil = 100 freeze = 0 #Calculating Boiling temperature in Fahrenheit & to print tb = boil * (9/5) + 32 print('Water Boiling temperature in Fahrenheit:', tb) #Calculating Boiling temperature in Fahrenheit & to print tf = freeze * (9/5) + 32 print('Water Freezing temperature in Fahrenheit:', tf) #defining the boiling and freezing temp in Celsius boil = 100 freeze = 0 #Calculating Boiling temperature in Fahrenheit & to print tb = boil * (9/5) + 32 print('Water Boiling temperature in Fahrenheit:', tb) #Calculating Boiling temperature in Fahrenheit & to print tf = freeze * (9/5) + 32 print('Water Freezing temperature in Fahrenheit:', tf)

#2nd program

<!-- wp:code --> <pre class="wp-block-code"><code># to accept amount amt = float(input("Enter amount lent:")) # to accept period & rate period = float(input("for how many period?:")) rate = float(input("What rate of interest is applicable for per year?")) # to calculate simple interest si = (amt * period * rate) / 100 # tocalculate amount payable amt_pay = amt + si # to print print("Simple Interest :", si) print("Net Amount Payable:", amt_pay) </code></pre> <!-- /wp:code -->

## Episode 13

#1st program

x = 55 print(x>50)

#2nd program

x = 55 print(x < 25)

#3rd program

x = int(input("Enter any number:")) if x > 55: print("Your number is greater than 55")

#4th program

x = int(input("Enter any number")) if x > 55: print("Your number is greater than 55") if x < 55: print("Your have entered number less than 55")

#5th program

x = int(input("Enter any number")) if x > 55: print("Your number is greater than 55") else: print("Your have entered number less than 55")

### Episode 14

#1st program

name = input("name of the candidate ") age = int(input("Enter age ")) if age >= 18: print(name + " is eligible to apply for a driving license") else: print(name + " is minor has to wait!!")

#2nd program

percentage = float(input("Enter percentage of a student ")) if percentage >= 35: print("Student Is passed") else: print("Student is failed")

### Episode 15

#1

n = int(input("Enter a number:")) if n % 4 == 0: print("number " + str(n) + " is divisible by 4") else: print("number " + str(n) + " is not divisible by 4")

#2

n = int(input("Enter a number:")) if n % 4 != 0: print("number " + str(n) + " is not divisible by 4") else: print("number " + str(n) + " is divisible by 4")

#3

train_type = input("Please enter type of train for Mumbai to Delhi:") if train_type == "Rajdhani": ticket = 2500 else: ticket = 1500 print('Ticket for Mumbai to Delhi is ', ticket)

## Episode 16 to Episode 20 Python Sample Code

### Episode 16

#1

name = input("Enter name:") age = int(input("Age?")) score = float(input("Score in final exam?")) if age >= 18: if score >= 60: print("Candidate "+ name + "is eligible") else: print("Sorry, you are not eligible") else: print("Sorry, you are not eligible")

#2

name = input("Enter name:") age = int(input("Age?")) score = float(input("Score in final exam?")) if age >= 18 and score>=60: print("Candidate " + name + " is eligible") else: print("Sorry, you are not eligible")

### Episode 17

#1

name = input("Enter name:") score = float(input("Score in final exam?")) experience = int(input("How much years of experience?")) if score >= 60 or experience >= 2: print(name, "is eligible for job") else: print(name, "is not eligible")

#2

t1 = int(input("Enter marks of test 1:")) t2 = int(input("Enter marks of test 2:")) t3 = int(input("Enter marks of test 3:")) if t1 >= 15 and t2 >= 15 and t3 >= 15: print("You are Pass") else: print("You are Fail")

#3

t1 = int(input("Enter marks of test 1:")) t2 = int(input("Enter marks of test 2:")) t3 = int(input("Enter marks of test 3:")) if t1 < 15 or t2 < 15 or t3 < 15: print("You are Fail") else: print("You are Pass")

### Episode 18

#1

a=5 b=11 a==b print(a==b)

#2

a=5 b=11 a==b print(not a==b)

#3

age = int(input("Enter age of the candidate")) if not age>=18: print("Sorry!! You are not eligible for license") else: print("You are eligible for license")

### Episode 19

Calculate Discount of book

book_type=input("Enter type of book to get the offer") if book_type == "Academic": print("Buy one get one free") elif book_type == "Children": print("3 books free") elif book_type == "Reference": print("Rs. 50 less in price") elif book_type == "Novel": print("Rs. 20 less in price") elif book_type == "Scientific": print("Gift Coupon available") else: print("Sorry!! no discount on this book")

### Episode 20

Calculate Percentage

percentage =float(input("Enter percentage")) if percentage >=60: grade ='A' elif percentage >=45: grade='B' elif percentage >=35: grade='C' else: grade='D' print('Grade:',grade)

## Episode 21 to Episode 25 Python Sample Code

### Episode 21

#1

worker_name=input("Enter name of the worker") worker_type=input("Enter worker type (skilled/unskilled)") hours_worked=float(input("Enter hours worked")) if worker_type =='Skilled': if hours_worked<=8: wages=hours_worked*100 else: wages=(8*100)+(hours_worked-8)*150 else : if hours_worked<=8: wages=hours_worked*80 else: wages=(8*80)+(hours_worked-8)*100 print("Wages:", wages)

### Episode 22

#1

roll_no=input("Enter roll Sutdent’number") name=input("Enter name of Student") english=int(input("Enter marks in English")) maths=int(input("Enter marks in Maths")) science=int(input("Enter marks in science")) total=english+maths+science per=(total*100)/300 if english >= 35 and maths >= 35 and science >= 35: remark = "Pass" if per >= 60: grade = "A" elif per >= 45: grade = "B" else: grade = "C" else: remark="Fail" grade="-" print("Total:%d\nPercentage:%.2f\nRemark:%s\nGrade:%s" % (total,per,remark,grade))

### Episode 23

#1

roll_no=input("Enter roll Sutdent’number") name=input("Enter name of Student") english=int(input("Enter marks in English")) maths=int(input("Enter marks in Maths")) science=int(input("Enter marks in science")) total=english+maths+science per=(total*100)/300 if english >= 35 and maths >= 35 and science >= 35: remark = "Pass" if per >= 60: grade = "A" elif per >= 45: grade = "B" else: grade = "C" else: remark="Fail" grade="-" print("Total:%d\nPercentage:%.2f\nRemark:%s\nGrade:%s" % (total,per,remark,grade))

#2

x=int(input("Enter any number")) if 50<x<100: print("Number is in the range") else: print("Number is not in the range")

### Episode 24

#1

import math result = math.sqrt(4) print(result)

#2

num =int(input("Enter number")) result = math.sqrt(num) print(result)

#3

import math a=input("Enter value for a") b=input("Enter value for b") a=int(input("Enter value for a")) b=int(input("Enter value for b")) math.sqrt(a**2+b**2) solution=math.sqrt(a**2+b**2) print("The solution for the equation",solution)

### Episode 25

Calculate square root

import math as m a=int(input("Enter value for a")) b=int(input("Enter value for b")) solution=m.sqrt(m.pow(a,2)+m.pow(b,2)) print("The solution for the equation ",solution)

Area of circle

import math as m radius = float(input("Enter radius of circle")) area = m.pi * m.pow(radius,2) print("Area of Circle is",area)

Factorial of number

import math as m n = int(input("Enter a number")) f = m.factorial(n) print("Factorial of",n,"is",f)