0% found this document useful (0 votes)
5 views

Test_jupyter_notebook

The document is a tutorial on using Jupyter Notebook for learning Python, covering various topics such as basic operations, strings, comments, variables, input, conditional logic, type conversion, functions, loops, and importing libraries. It includes code examples and explanations for each topic, aimed at beginners. Additionally, it discusses common errors encountered in Python programming.

Uploaded by

affan.p3b
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Test_jupyter_notebook

The document is a tutorial on using Jupyter Notebook for learning Python, covering various topics such as basic operations, strings, comments, variables, input, conditional logic, type conversion, functions, loops, and importing libraries. It includes code examples and explanations for each topic, aimed at beginners. Additionally, it discusses common errors encountered in Python programming.

Uploaded by

affan.p3b
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/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

In [ ]: print ('hello world')


print ("we are learning python with Affan")
print ('''I am in the office of my father and i am learning with him and his freinds'''
print ("I am learning to get good education and get a visa to study at Australia")
print ("My father is a great helper in my Education")
print ("i am tired")
print ("I am hungry")
print ("i am fresh")
print ("Now i can do work")
print ("its time to go home")
print ("i will return tommorow")

04. Comments

In [ ]: # print ('hello world')


# print ("we are learning python with Affan")
print ('''I am in the office of my father and i am learning with him and his freinds'''
print ("I am learning to get good education and get a visa to study at Australia")

05. Variables

1 of 5 23/06/2024, 1:06 pm
Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/Test_jupyter_notebook.html

In [ ]: # Variables are objects containing specific values


x=8
print (x)

y= "we are learning python with Affan"


print (y)

x=x+10
print(x)

y=y+" and its super easy"


print(y)

z=0.5
print(z+1)

# finding the type of variable


print(type(x))
print(type(y))
print(type(z))

# Rules to assign a variable


# • Variables should be of letters, numbers or underscores
# • Don’t start variable with numbers
# • Spaces aren’t allowed
# • Don’t use functional keywords for variables
# • Should be short and meaningful
# • Should be case sensitive (lowercase is preferred)

# del is used to delete variables

06. Input Variables

In [ ]: # # input function is used


name=input("What is your name ")
greetings="Hello! , nice to meet you"
print(greetings, name)

name=input("whats your name buddy ")


age=input("whats your age? ")
print("Hello! ",name,"You are still young")

07. Conditional Logics

2 of 5 23/06/2024, 1:06 pm
Test_jupyter_notebook file:///C:/Users/EliteBook/Downloads/Test_jupyter_notebook.html

In [ ]: # logical operators are either true/false or yes/no or 0/1


# equal to ==
# not equal to !=
# less than <
# greater than >
# less than equal to <=
# greater than equal to >=

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)

08. Type conversion

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))

09. If Else Elif Statements

In [ ]: age=int(input("What is your age? "))


age_req_at_school=5
# question is that can rayyan go to school
if age == age_req_at_school:
print("Rayyan can go to school")
elif age>17:
print("Rayyan should enter college")
else:
print("Rayyan cannot go to school")

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)

# print_codanics("We are learning python in our vacations")

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

In [ ]: # While loops and For loops


# 1. While loops
x=0
while (x<10):
print(x)
x=x+1

# 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

12. Import Libraries

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))

# important libraries include numpy, pandas

x=(100,150,200,200,250,200,150)
print("the median value is",statistics.median(x))

13. Trouble shooting

In [ ]: # print(We are learning python with ammar) #syntax error (means language error)

print(25/0) #runtime error / zero division error (math error)

name= "Affan"
print ("Hello name") # semantic error (not expected result)

5 of 5 23/06/2024, 1:06 pm

You might also like