Adobe Scan 02 Dec 2024
Adobe Scan 02 Dec 2024
• Uses:
0
Performing arithmetic
operations (addition,
subtraction, multiplication,
etc.).
Python
11 :52 ~ W 1.00
V' KB/5
Vo
lTE
:sGII
II
0 90'¾0
ChatGPT
• 1:.xamp1e l;oae:
X = 10
y = -5
result= x + y # result is 5
2. float (Floating-point
number)
• Uses :
e Message
11:53 : ~ 21 .0 Vo <SGII
V KB/S lTE II
Q 893/c0
ChatGPT
• Uses:
• Example Code:
pi= 3.14159
radius= 5.0
area= pi * radius ** 2 #
area is 78 . 53975
3. boo/ (Boolean)
• Examples: v alse
•· -- --
G Message
This creates a copy that
others can chat with
3. boo/ (Boolean)
• Uses:
• Example Code:
is_valid = True
if is _ vali~ ·
prin t ' 55 granted" )
# This p V f is valid is
True.
Message
11:53 ~ W 4 .00
W' KB/S
Vo
lTE
:sG
II
II 0 89'¾0
ChatGPT
• Example Code:
is_valid = True
if is _valid :
print ( ''Access granted'' )
# This prints if is valid is
True.
4. None (NoneType)
• Examples : None
• Uses:
e Message
e a link to chat.
creates a copy that
s can chat with
uses:
o Indicates that a variable has
no value assigned yet .
functions.
o Helps manage optional or
missing data in a program-
Example code:
CJ copY code
python
result= None # Indicates no
result
def yet (value= None ) :
compute
if value is None :
return "NO input
provided"
return value* 2
int
float
bool
None
• Message
Discu ss the role of condi tional
state ment s in pytho n
Role of Conditional
Stat eme nts in Python
1. Decis ion V J:
ontc ,:,lln•M
-'"tinn, :,I ct,:,tom
0 r,-,nn•
W 16.0 Vo :SGII
V KB/S LIE I I
Q 390
ents
ision Making:
Example:
age = 18
if age >= 18 :
print ( "You are
eligible to vote." )
else :
print ( ''You are not
eligible to vote." )
ntrol Flow:
Examp v
flow by executing specific
code blocks while skipping
others, based on logical
expressions.
0
Example:
Python
Ll Copy code
number = 1 o
if number > 0 :
print ( "Positive
number" )
elif number < 0 :
print ( "Negative
number" )
else :
print ( "Zero" )
0
Examp h.
G Message
Python
LI Copy code
o Example:
for i in range ( 10 ) :
if i % 2 == 0 :
continue # Skip
even numbers
print (i) # Prints
only odd numbers
5. Dynamic Functionality:
0 Example:
e Message
11:56 ~ ~ 016
V
Vo
KEHS LTE
SG
111
IQ 89o/c0
ChatGPT
continue # Skip
even numbers
print (i) # Prints
only odd numbers
5. Dynamic Functionality:
o Example:
if temp < O:
return ''Freezing''
elif O <=temp <= 20 :
return "Cold"
elif 20 < temp <= 30 :
return "Warm"
else :
return "Hot"
print (classify_temperatur
e( 25 )) # Output: Warm
Message
WO 26 V 5G I'\
V KB/S Lli 1111 v 88%
hatGPT
1 . try Block
essage
11:59 : ~ O 47 Vo
v KB/s m SG I
• 1I ,V, 883/co
ChatGPT
1. try Block:
Example:
try :
x = int ( input ( ''Enter a
number: " ))
2. except Block:
G Message
Python L) Copy code
try :
X = 1 / 0
except ZeroDivisionError:
print ( ''Division by
zero is not allowed.")
ChatGPT
o Example:
try :
x = int ( input ( ''Enter
a number : " ))
except ValueError:
print ( "Invalid input.
Please enter a number . " )
else :
print ( f''You entered :
{ x} " )
e tv,essage
11 :59 ~ W 3.00
V' KB/S
Vo
lTE
SG
II
II l) 88'¾0
ChatGPT
o Example:
try :
file=
open ( ''data.txt'' , ''r'' )
data= file.read()
e xcept FileNotFoundError :
print ( "File not
found . " )
finally :
file.close() #
Ensures the file is
always closed
e Message
12:00 : ~ 792 Vo .SG
V' KB/S LTE II II 'V, 883/c0
ChatGPT
1. Prevents Crashes :
2. Improves Debugging :
4I Message