Lecture-1 (Day 1)
Lecture-1 (Day 1)
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
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