Test_jupyter_notebook
Test_jupyter_notebook
html
Python ka chilla
How to use jupyter notebook
Basics of python
01. First Program
In [ ]: print (2+3)
print ("hello world")
print ("we are learning python with Affan")
2. Operators
In [ ]: print(2+3)
print(5-3)
print(4*2)
print(9//3)
print(9/3)
print(9%2)
print(2**3)
03. Strings
04. Comments
05. Variables
1 of 5 23/06/2024, 1:06 pm
Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/Test_jupyter_notebook.html
x=x+10
print(x)
z=0.5
print(z+1)
2 of 5 23/06/2024, 1:06 pm
Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/Test_jupyter_notebook.html
print(10==7)
print(10>7)
age_required=6
rayyan_age=int(input("How old is rayyan"))
# or you can convert type like, rayyan_age=int(rayyan_age)
print(rayyan_age==age_required)
In [ ]: # implicit conversion
x=10
y=0.5
x=x*y
print(x, "The type of x is: ", type(x))
# explicit conversion
rayyan_age=input("What is your age? ")
rayyan_age=int(rayyan_age)
print(type(rayyan_age))
10. Functions
3 of 5 23/06/2024, 1:06 pm
Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/Test_jupyter_notebook.html
In [ ]: # defining a function
# def print_codanics():
# text="We are learning python in our vacations"
# print (text)
# print (text)
# print (text)
# print (text)
# print (text)
# print_codanics()
# def print_codanics(text):
# print (text)
# print (text)
# print (text)
def school_calculator(age):
if age >= 5 and age < 17:
print("Rayyan can go to school")
elif age>17:
print("Rayyan should enter college")
else:
print("Rayyan cannot go to school")
school_calculator(18)
def future_age(age):
new_age=age+20
return new_age
future_predicted_age=future_age(16)
print (future_predicted_age)
11. Loops
# 2. for loop
for x in range(0,10):
print (x)
days=("Mon","tue","Wed","Thu","Fri","Sat","Sun")
for i in days:
# if (i=="Fri"):break #stops the loop
if (i=="Fri"):continue # skips fri
print(i)
4 of 5 23/06/2024, 1:06 pm
Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/Test_jupyter_notebook.html
In [ ]: import math
print("The value of pi is", math.pi)
import statistics
x=(150,200,250,300,350)
print("The mean value is",statistics.mean(x))
x=(100,150,200,200,250,200,150)
print("the median value is",statistics.median(x))
In [ ]: # print(We are learning python with ammar) #syntax error (means language error)
name= "Affan"
print ("Hello name") # semantic error (not expected result)
5 of 5 23/06/2024, 1:06 pm