[go: up one dir, main page]

0% found this document useful (0 votes)
16 views16 pages

Lecture-1 (Day 1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views16 pages

Lecture-1 (Day 1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

PROJECT

ON
HEART DISEASE PREDICTION
(Lecture-1)
(Basics of Python)
Presented by
Dr. Debasis Mohapatra
Assistant Professor
Dept. of CSE, PMEC, Berhampur
Hello world Program

 Use any IDE (Spyder, Jupyter Notebook, Google Colab (for online with
google account)).

print("Hello, World!")

 Output:
 Hello, World!
Variables
 Python has no command for declaring a variable.
 In Python, variables are created when you assign a value to it.

 x=9
y=10.7
print(x)
print(y)
 Output:
9
10.7
Variables

 x=9
y=10.7
print("x = %d,y = %f" %(x,y))

 Output:

x = 9,y = 10.700000
Comments

 Comments can be used to explain Python code.


 Comments can be used to make the code more readable.
 Comments can be used to prevent execution when testing code.
 Single line comment
#This is a comment
print("Hello, World!")
 Output:
Hello, World!
 Multi line comment
"""
This is a comment
on basic printing
"""
print("Hello, World!")
 Output:
Hello, World!
Some basic datatypes

 In programming, data type is an important concept.


 Variables can store data of different types, and different types can do
different things.
 Example:

Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set


Some basic datatypes (Example)

 x = 10
print(type(x))
Output:
<class 'int’>
 x = 1.8
print(type(x))
Output:
<class ‘float’>
 x = "How are you?"
print(type(x))
Output:
<class 'str'>
List Datatype
 Lists are used to store multiple items in a single variable.
 Lists are created using square brackets.
 Difference than Array: List may contain different types of data.
Some commands on list

l=[1,2,"abcd", 20.7]
print(l)
print(l[0])
print(l[0:2])
print(l[-1])
l.append(4)
print(l)
l.remove(2) # remove according to value
print(l)
del l[2] #remove according to location
print(l)
l.reverse() #reverse a list
print(l)
print(len(l))
Some commands on list

 Output:
[1, 2, 'abcd', 20.7]
1
[1, 2]
20.7
[1, 2, 'abcd', 20.7, 4]
[1, 'abcd', 20.7, 4]
[1, 'abcd', 4]
[4, 'abcd', 1]
3
if statement
 if condition:
expression

 Example:
 #Check a number is positive
n=int(input("Enter a number"))
if n>0:
print("%d is +ve" %(n))
if-else statement
 if condition:
expression1
else:
expression2

 Example:
 #Check a number is even or odd
n=int(input("Enter a number"))
if n%2==0:
print("%d is even" %(n))
else:
print("%d is odd" %(n))
if-elif-else statement
 if condition1:
expression1
elif condition2:
expression2
else:
expression3

 Example:
#Check a number is zero, even nonzero or odd
n=int(input("Enter a number"))
if n%2 != 0:
print("%d is odd" %(n))
elif n==0:
print("It is zero(%d)" %(n))
else:
print("%d is even nonzero" %(n))
for loop

 A for loop is used for iterating over a sequence.


 #print elements of the list
x=["cat",1,3,"ball"]
for i in x:
print(i)

 #print elements of the list using location


x=["cat",1,3,"ball"]
for i in range(len(x)):
print(x[i])
for loop
 #print all even numbers in the range [10,100]
for i in range(10,101):
if i%2==0:
print(i)
while loop

 With the while loop we can execute a set of statements as long as a


condition is true.
 #print all even numbers in the range [10,100]
i=10
while i<=100:
if i%2==0:
print(i)
i=i+1

You might also like