Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Python

Uploaded by

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

Python

Uploaded by

kashyapnaveen988
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

PYTHON

Basics
Why Python ?

Supportive
Open Simple Flexible community with
Language plenty of
Source Syntax documentation

•matplotib for plotting charts and graphs


•SciPy for engineering applications, science,
Used in Big data,
and mathematics
Versatility, Efficiency,
•NumPy for scientific computing
•Django for server-side web development Reliability, and Speed
Machine Learning and Interpreter
Cloud Computing
Modes
Interactive Script
print() function
Not a function in Python Became a function in
version 2 and less and thus python version 3 and
no parenthesis required above

Syntax:
print(message1,message2,…)

Example:
print(‘Good Morning’,’Everyone’)

Output:
Good Morning Everyone
Smallest Building block
in any
programming language

Tokens Literals Operators Keywords Identifier Delimiters


Must start with a character

Can’t be a keyword

Can’t have space


Name to
Tokens

Identifier variable or an Can’t start with a number


object
Only special character allowed
is Underscore ( _ )

Unlimited Length
Examples of…
Valid Identifiers Invalid Identifiers
true True
_Geeta True&
Num123 if
One_123 5num
LEN 5_Num
Len Num 123
FALSE Y*8
O1N2 T_
END class
If int
X=10
Y=20

X,Y=10,20
Identifier
Tokens

Declaration X=10;Y=20

X=Y=20
+ (Addition)

- (Subtraction)
* (Multiplication)
Tokens

Operators Arithmetic / (Division)


// (Floor Division)
% (Remainder)
** (Exponentiation)
> (Greater Than)
> (Greater than OR Equal to)
< (Less Than)
Tokens

Operators Relational <= (Less than OR Equal to)


!= (Not Equal To)
== (Comparison)
= (Assignment)
Example
Program Output
X,Y=10,20
print(X>Y) False
print((X-Y)<0) True

print("Hena"!="Heena") True
print("Bharat">"bharat") False
print("60"<"66") True
Tokens

Operators

Logical

not and or
Example
Program Output
Num1=90
Num2=34
print(Num1>10 and Num2<34) False

X=9
Y=45
print(X!=Y and not Y<X) True
Example
Program Output
a = 13 False
b = 33
# a > b is False True
print(a > b) False
# a < b is True
print(a < b)
True
# a == b is False False
print(a == b) True
# a != b is True
print(a != b)
# a >= b is False
print(a >= b)
# a <= b is True
print(a <= b)
Tokens
Augmented
Assignment

Operator Implementation Explanation Result

+= A+=B A=A+B ; print(A) 7


A=5 -= A-=B A=A-B ; print(A) 3
B=2 /= A*=B A=A*B ; print(A) 10
//= A/=B A=A/B ; print(A) 2.5
**= A**=B A=A**B; print(A) 25
%= A%=B A=A%B ; print(A) 1
in
Tokens

Operators Membership
not in
is
Tokens

Operators Identity
not is
() Brackets, list display, dictionary display, set
display
** Exponentiation
*, /, //, % Multiplication, Division, Floor Division,
Remainder (All same, evaluated which
comes from left to right)
+,- Addition, Subtraction ((All same, evaluated
Tokens

which comes from left to right)

Operator in, not


in, is,
Comparison Operator including
membership and identity tests
Precedence is not,
<, <=, >,
>=, !=,
==
not Boolean NOT
and Boolean AND
or Boolean OR
String that occurs
in the form of a
Tokens

() [] {}
Delimiters
space, comma,
semicolon, colon, , : . ;
and any other
character
Example
Program: of swapping two numbers
One Way Other Way
X,Y=10,20 X,Y=10,20
Z=X X,Y=Y,X
X=Y print(X,Y,sep=‘*’)
Y=Z
print(X,Y,sep=‘*’) 20*10
input() : Used to accept data
• Accepts string data by default
• Message can be provided with function
Example of accepting string
X=input('Enter First Name')
Y=input('Enter Last Name')
print(X,Y)

Example of accepting Numeric Value


X=int(input('Enter a Number'))
Y=int(input('Enter another'))
print(X+Y)
print() with parameters
sep → For separating multiple values with single print() with a string. Default is a single column space
end → Terminating the print() with the given string. Default is line break ‘\n’

Example Output
X=12;Y=20
print(X,Y,sep=‘and’) 12and20
print(X+Y,end=‘printed’) 32printed

X=12;Y=20
print(X,Y,sep=‘+’,end’=’)
print(X+Y) 12+20=32
Conditional Statement
• if
• if else
• if elif else

Syntax
if <condition> : Block starts if <condition> : Block starts
….statements…. ….statements….
else: Block for else
….statements….
Conditional Statement
Syntax
if <condition1> : Block starts
….statements….
elif <condition2>: Block for elif
Note
Else not compulsory
….statements….
As soon as the True condition is found,
elif <condition3>: Block for elif the rest of the conditions are ignored
….statements….
.
.
else: Block for else
….statements….
Conditional Statement
Nested if Example
if <condition1> : Program to Display grade
if <condition>: 90-100 A1
if <condition>: 80-90 A2
….statements…. 70-80 B1
else: 60-70 B2
….statements….
50-60 C1
else:
40-50 C2
….statements….
<40 D
else:
….statements….
Single Liner if statement
<statement if True condition> if condition else <statement if False>

Example
#Program to check if number accepted is even or odd

A=int(input())
print("Even") if A%2==0 else print("Odd")
Examples
name = "John"
age = 23
if name == "John" and age == 23:
print("Your name is John, and you are also 23 years
old.")
if name == "John" or name == “Rick":
print("Your name is either John or Rick.")
Examples
# Code to check for odd or even
x = int(input("Please enter first integer: "))
if x%2 == 0:
print(“ x is even”)
else:
print(“x is odd”)
Questions

1. Program to accept a number and check if it’s a multiple of 7 or not.


2. Accept the year and check if it's a leap year or not. (A leap year is
the one which is either divisible by 400 or if divisible by 4 and not
divisible by 100.)
3. Write a menu driven program to simulate a four function calculator.
The program should yield the following output.
Menu - 1.Add 2.Subtract 3.Multiply 4.Divide

Sample Output
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15 * 14 = 210
Loops
for while
Can never go into
Can go into infinite case
infinite case

Uses range function


for iteration or We use condition
membership operator

Condition has to be Condition can have any


numeric and for finite data type and used when
number no certainty
Programs that should be done

1. Program to print first 10 natural numbers.


2. Print first 10 multiples of 3.
3. Print sum of first N natural numbers.
If N=5, then the output should be 1+2+3+4+5=15
4. To print the reverse of a number N
5. To check if the number is a Palindrome or not (If the reverse of a
number is same as the number, it is called a Palindrome)
6. To accept a number N and check if it’s a prime number
7. To display factorial of a number N. (Factorial of a number is the
product of numbers from 1 till N)
8. Display first N terms of Fibonacci series. (It’s a series, where the
next term is generated by adding previous two terms)
Examples
Program to add natural numbers upto n ,

sum = 1+2+3+...+n

n = int(input("Enter n: "))# To take input from the user


sum = 0 # initialize sum and counter
i = 1
while i <= n:
sum = sum + i
i = i+1 # update counter
print("The sum is", sum) # print the sum
Jump Statements
break
Used to terminate a loop

pass
Practically does nothing. Continues with the rest
of the statements in loop.

Continue
Jumps for the next iteration.
Example
pass Continue break
print("--Using print("--Using print("--Using
\"pass\"--") \"continue\"--") \"break\"--")
for n in range(1,6): for n in range(1,6): for n in range(1,6):
if n == 3: if n == 3: if n == 3:
pass continue break
print(n) print(n) print(n)

--Using "pass"– --Using ”continue"– --Using ”break"–


1 1 1
2 2 2
3 4
4 5
5
Loop with else

for I in range(…..): while True:


..statements ..statements..
else: else:
..statements.. ..statements..

Note: The else of a loop will get executed if the loop completes all the
iterations, which means the break is not encountered
Nested Loop
Loop inside another loop
For every value of outer loop the inner loop is executed completely
Used to solve Pattern Questions
1 1 1234 1234 4321 1
12 21 234 123 321 23
123 321 34 12 21 456
1234 4321 4 1 1 78910

1 4 1111 1111 * 5
22 33 222 2222 ** 1015
333 222 33 3333 *** 202530
4444 1111 4 4444 **** 35404550
Nested Loop
Basic Rule :
Outer Loop for number of rows
Inner Loop for number of values in each row

I J
for I in range(1,3):
for J in range(1,3):
1 1
print(I,J,sep='+',end=',') 2
print()
1+1,1+2,2+1,2+2, 2 1
2
Iterable
Mutable Immutable
List L=[1,3,5,7]
Tuple T=(4,8,1,2)
Dictionary D={‘a’:12,’b’:90 }
String S=‘Data‘
Set S={5,8,9 }
Mutable
List
Data is stored within Square Brackets.
It is a heterogenous collection of data.
Each value is called Element
Each element is extracted using index number starting from 0

L=[ ] #List Object with no element. Also called as Blank list


Immutable
Tuple

Data is stored within Round Brackets.


It is a heterogenous collection of data.
Each value is called Element
Each element is extracted using index number starting from 0

T=( ) #Tuple Object with no element. Also called as Blank Tuple

Tuple with single element is declared as T=(10,)


Immutable
String

Data is stored within Single or double quotes.


It is collection of multiple characters.
Each character is called as element.
S=”Data"
len Concatenation Repetition Membership

* Operator in, not in


+ Operator Keywords
Used
Used Used
Returns
the total
number Iterable Checks for
of Combines
elements the
elements iterables of
in the are repeated availability of
same type to
iterable to generate a value in a
generate
a new given
new iterable
iterable Iterable.
len Concatenation Repetition Membership
A=‘YES’ A=”Good”;B=”Day” A=”Good” A=”Good”
print(len(A) print(A+B) print(A*3) print(“G” in A)
#3 #GoodDay #GoodGoodGood #True

L=[1,5,7,2] A=[12,56,56] A=[12,56] A=[12,56,89]


print(len(A)) B=[8,”N”] print(A*2) print(56 in A)
#4 print(A+B) #[12,56,12,56] #True
#[12,56,56,8,”N”]

T=(1,5,7,2,8) A=(12,56,56) A=(12,56) A=(12,56,89)


print(len(A)) B=(8,”B”) print(A*2) print(6 not in A)
#5 print(A+B) #(12,56,12,56) #True
#(12,56,56,8,”B”)
Slicing in iterables
Slicing is a feature which allows you to extract a part of the string using the index
numbers 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
H A V E A G O O D D A Y
-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1

iterable.[start:end:step]
String Functions
capitalize(): Returns a copy of this string with only the first character capitalized.

title(): Returns string by capitalizing first letter of every word in the string
S=
lower(): Returns string by converting every character to lowercase

upper(): Returns string by converting every character to uppercase

swapcase(): Returns a string in which the lowercase letter is converted to


uppercase and uppercase to lowercase

replace(old, new): Returns a new string by replacing the occurrence of old


stringwith new string
String Functions
>>> s = "friendly python"
>>> s.capitalize()
'Friendly python'
>>> s.title()
'Friendly Python'
>>> s.lower()
S=
'friendly python'
>>> s.upper()
'FRIENDLY PYTHON'
>>> s.swapcase()
'FRIENDLY PYTHON'
>>> s
'friendly python'
>>> s.replace("friend", "Python")
'Pythonly python’
>>> s
'friendly python'
FUNCTIONS/METHODS IN LIST

list.append()
The method list.append(x) will add an item (x) to the
end of a list.

>>> fruits = ['banana', 'apple’, 'mango','orange','watermelon','grapes']


>>> print(fruits)
['banana', 'apple', 'mango', 'orange', 'watermelon',
'grapes']
FUNCTIONS/METHODS IN LIST

list.insert()
The list.insert(i,x) method takes two arguments,
with i being the index position you would like to
add an item to, and x being the item itself.

>>> fruits.insert(1,'pear')
>>> print (fruits)
['banana', 'pear', 'apple', 'mango', 'orange',
'watermelon', 'grapes', 'Pineapple']
FUNCTIONS/METHODS IN LIST

list.extend()
If we want to combine more than one list, we can use
the list.extend method, which takes in a second list
as its argument.

>>> more_fruits = ['cherry','strawberry']


>>> fruits.extend(more_fruits)
>>> print(fruits)
['banana', 'pear', 'apple', 'mango', 'orange',
'watermelon', 'grapes', 'Pineapple', 'cherry',
'strawberry']
FUNCTIONS/METHODS IN LIST

list.remove()
This method removes the first item in a list whose value is
equivalent to x.

>>> fruits.remove('orange')
>>> print(fruits)
['banana', 'pear', 'apple', 'mango', 'watermelon',
'grapes', 'Pineapple', 'cherry', 'strawberry']
>>> fruits.remove('Mango')
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
fruits.remove('Mango')

5 / GS2
ValueError: list.remove(x): x not in list
FUNCTIONS/METHODS IN LIST

list.pop()
The list.pop([i]) method returns the item at the given index
position from the list and then removes that item. The
square brackets around the i for index indicates that this
parameter is optional, so if we don’t specify an index , the
last item will be returned and removed.

>>> fr = fruits.pop(3)
>>> print(fr)
mango
>>> fru = fruits.pop()
>>> print(fru)
strawberry
FUNCTIONS/METHODS IN LIST

list.index()
list.index(x), where x is equivalent to an item
value, to return the index in the list where that
item is located. If there is more than one item with
value x, this method will return the first index
location.

>>> print(fruits.index('grapes'))
4
>>> x = fruits.index('grapes')
>>> print(x)
4
FUNCTIONS/METHODS IN LIST

list.copy()

To make a copy of the list.


>>> fruits2 = fruits.copy()
>>> print(fruits , fruits2)
['banana', 'pear', 'apple', 'watermelon',
'grapes','Pineapple', 'cherry'] ['banana',
'pear', 'apple','watermelon', 'grapes',
'Pineapple', 'cherry']
FUNCTIONS/METHODS IN LIST

list.reverse()
We can reverse the order of items in a list by using
the list.reverse() method.
>>> fruits.reverse()
>>> print(fruits)

['cherry', 'Pineapple', 'grapes', 'watermelon',


'apple','pear', 'banana']
FUNCTIONS/METHODS IN LIST

list.count()
The list.count(x) method will return the number of
times the value x occurs within a specified list.
>>> print(fruits.count('cherry'))
1
>>> fruits.append("cherry")
>>> print(fruits.count('cherry'))
2
FUNCTIONS/METHODS IN LIST

list.sort()

To sort the items in a list.


>>> fruits.sort()
>>> print(fruits)
['Pineapple', 'apple', 'banana', 'cherry',
'cherry',
'grapes', 'pear', 'watermelon']
>>> print(fruits.sort())
None
FUNCTIONS/METHODS IN LIST

Predict the output [‘apple', 'plum',


'banana']
fruits = ["apple", "plum", "banana"]
['apple', 'plum',
print(fruits)
fruits.append("mango") 'banana', 'mango']
print(fruits) ['apple', 'plum',
fruits.pop() 'banana']
print(fruits) ['apple', 'plum',
fruits.append("grape") 'banana', 'grape']
print(fruits)
['apple', 'plum',
fruits.pop(2)
print(fruits) 'grape']
Try it! Write a menu driven program to perform the following . Use
library functions.
1) At runtime add 5 elements (movie names) to a list and
display it
2) Sort the list and display the list before and after the sort .
3) Insert a new movie name at the desired location &
display the modified list
4) Check the presence of a movie name in the given list . If
present display its position else display "Movie not found" .

The program should work as many times the user wants .


(Use loops)
Nested List

0 1 2 3 4

A=[[1,4,5,3],[5,22,51],[7,34,6],89,90]

0 1 2 3 0 1 2 0 1 2

A=[[1,4,5,3],[5,22,51],[7,34,6],89,90]
for i in A: [1, 4, 5, 3]
if type(i)==list: [5, 22, 51]
print(i)
[7, 34, 6]
else:
Not a List
print(“Not a list”)
Not a List
FUNCTIONS/METHODS IN TUPLE

len ( ) Returns the no of elements in a Tuple

L=(2,3,4)
print(len(L)) #3
print(len((2,4,5)))#3
S=len(L)
W=len(L*3)
print(S,W) #3 9
FUNCTIONS/METHODS IN TUPLE

tuple ( )
Converts a given iterable into a list. If no iterable,
then blank list is created.

Tuple(iterable object)

a=tuple()
print(a) #( )
c=[1,2]
print(tuple(c))#(1,2)
b=12
#print(tuple(b)) #Not allowed
FUNCTIONS/METHODS IN TUPLE

count ( ) Returns the number of occurrences of a value

Tuple.count(value)

L=(1,2,3,3,2,2,1,3,5)
print(L.count(3)) #3
print(L.count(1)) #2
print(L.count(2)) #3
print(L.count(9)) #0

L=(1,2,3,(1,3),2,2,1,3,5)
print(L.count((1,3))) #1
FUNCTIONS/METHODS IN TUPLE

index (value, start, end )


Returns the first index of the value, if found, else raises
valueError

L=(1,2,3,5,2,11,6,5)
print(L.index(5))
print(L.index(5,0,3)) Output
print(L.index(5,0,4)) ?
print(L.index(6))
Nested Tuple

0 1 2 3 4

A=([1,4,5,3],(5,22,51),[7,34,6],89,90)

0 1 2 3 0 1 2 0 1 2

A[0][1]=?4 A[1][2]=?51 A[3]= ?89 A[2][2]= 6


?

A=([1,4,5,3],(5,22,51),[7,34,6],89,90)
Not a List
for i in A:
(5, 22, 51)
if type(i)==tuple:
Not a Tuple
print(i)
Not a Tuple
else: Not a Tuple
print(“Not a tuple”)
Mutable
Dictionary

Data is stored within Curly Brackets.


It is a heterogenous collection of data.
Each value is called item.
Item is a key value pair, separated with : (colon)
The key must be unique, while the values may be repeated.
The key can be any immutable object while Value can be immutable or mutable
object
Dictionary Declaration
D={} #Blank Dictionary
D1={‘A’:10,’B’:20,’C’:20} #Dictionary with 3 items
D2={1:”One”,5:”Five”,2:”Two”} #Dictionary with 3 items
D3={“Roll”:12,”Name”:’Ankita’}#Dictionary with 2 items
If the dictionary has more than one key with the same name, then the last key
value is stored in Dictionary

D={'a':1,'b':2,'a':22,'a':11,'b':1}
print(D) #{'a': 11, 'b': 1}
D={'a':1,'b':2,'a':22,'a':11,'b':1,'c':6,'b':"tt"}
print(D) #{'a': 11, 'b': 'tt', 'c': 6}
Common Functions in String, List, Tuple, Dictionary
len(String) len(List) len(Tuple) len(Dictionary)
#returns length of string #returns length of List #returns length of Tuple #returns length of Dictionary

String.count() List.count() Tuple.count()


#counts the occurrence of a #counts the occurrence of a value/item #counts the occurrence of a value/item in
substring in a list a tuple

String.index() List.index() Tuple.index()


#returns the index of a substring in a #returns the index of an item in a tuple
string else ValueError #returns the index of aa item in a list else ValueError
else ValueError

min(String) min(List) min(Tuple) min(Dict)


#returns the smallest character in a #returns the smallest item in a #returns the smallest item in a
#returns the smallest key in a dict which
string (as per ASCII code) homogenous list of items homogenous tuple of items have homogenous values in key

max(List) max(Tuple) max(Dict)


#returns the largest item in a #returns the largest item in a homogenous #returns the largest key in a dict which
max(String) homogenous list of items tuple of items

sum(Tuple)
have homogenous values in key

#returns the largest character in a sum(List) sum(Dict)


string (as per ASCII code) #returns the sum of all the items of list, #returns the sum of all the items of tuple, #returns the sum of keys of dict where
where items must be integers keys must be integers
where items must be integers

sorted(String) sorted(List) sorted(Tuple) sorted(Dict)


#returns the list of items sorted in #returns the list of dict keys sorted in
#returns the list of characters sorted in #returns the list of items sorted in ascending order
alphabetical order as per ASCII Code ascending order
ascending order
Modules in Python

sin(x) Returns the sine of x in radians.


math module
cos(x) Returns the cosine of x in radians.

import math tan(x) Returns the tangent of x in radians.

sqrt(x) Returns the square root of x.

pow(x,y) Returns x**y

fabs() Returns the absolute value (Positive


value) of the expression / number
Modules in Python

random() Returns the next random floating


point number in the range [0.0,
1.0]
math module
randint(a, b) Returns a random integer between
import random a and b inclusive

randrange(start, stop[, step]) Returns a random


integer from the range
Modules in Python

mean() – It returns the mean / average of the


given list of numbers passed as
parameters.
math module
mode() – Mode is the statistical term that
import statistics refers to the most frequently occurring
number found in a set of numbers.

median()– Returns the median (middle value) of


numeric data.
FUNCTIONS IN PYTHON

Single or series of commands written as a


separate section and given a name.
WHY FUNCTIONS ?
TYPES OF FUNCTIONS

USER DEFINED
BUILT-IN FUNCTIONS
FUNCTIONS (created
(For eg sqrt(), random()
using def keyword)
etc
CREATING USER DEFINED FUNCTIONS

POINTS TO REMEMBER

● Starts with the keyword def.


● Write the function name after def , followed by parentheses () .
● Function name may or may not have parameters .
● Functions may or may not return a value.
● Function must be defined before it is called
● Functions can return a single or multiple values .
FUNCTIONS RETURNING VALUES
● Can return single value

● Can return multiple values

● Multiple values are returned in the form of Tuple, if parentheses are not
specified
● To designate multiple value returning, you need to to enclose them in
appropriate brackets.

return x,y,z or return [x,y,z] will return {x,y,z} will


return(x,y,z ) will return the values return the values in
return the values in in the form of a the form of a
the form of a tuple list dictionary
Arguments and Parameters
in Functions
Arguments: The values which are
passed to the function while calling it

Parameters : The variables which


take the value of the arguments in a function
call.
Types of Arguments passed to a function

1. Required or Positional Arguments


2. Default Arguments
3. Keyword Arguments
4. Variable Arguments
Local and Global Variables

Variables which are


declared within a function
are its local variables and
are therefore accessible Variables which are
inside the block where defined outside the scope
they are declared. of a function are Global
Variables.
Local and Global Variables
def inside():
x=20 #local to function inside
print(“in funct “,x) #20 printed

x=10 #Global x with value 10


print(“Out func”,x) #Global x =10 printed
inside() #Function Call
print(“Out func”,x) #Global x =10 printed

Out func 10
Output: in funct 20
Out func 10
Rules for accessing the Local/Global Variables
1. Priority is always given to local variables

2. If there is no local variable then the global variable will be used

3. But the value of the global variable is not allowed to get changed
in local variable until explicitly specified.

4. If there is a local variable and a global variable with the same


name, then the function will use its respective local variable.

5. Order of accessing the local and global variables is very important.

6. Local variable of a function cannot be accessed from outside


Can I access Global Variable from a function and
change its value?
YES
def Fun(): The Value of C : 12
a,b=4,5
4 5 9
global c
c=a+b The Value of C now : 9
print(a,b,c)

c=12
print("The Value of C : ", c)
Fun()
print("The Value of C now :",c)
Can Local and Global variables with same name be
used in same function?
NO
def Fun(): ERROR!!!!
a,b,c=4,5,17
print(a,b,c)
global c (A variable cannot be
c=a+b both local and global
print(a,b,c) inside a function)
c=12
print("The Value of C : ", c)
Fun()
print("The Value of C now :",c)
Interesting Programs to try in Python
import pywhatkit
pywhatkit.sendwhatmsg(‘+911234567890','Hello',18,5)

Whatsapp message Hello will be sent to


+911234567890 at 18 hour and 5 mins
Interesting Programs to try in Python
import calendar
year =int(input("Enter the year of the requd calendar "))
month = int( input("Enter the month of the requd calendar "))
print(calendar.month(year,month))

See the result…..


Interesting Programs to try in Python
import pyautogui
num=int(input("Enter a value to divide 100"))
if num == 0:
pyautogui.alert(" Alert!!! 100 can’t be divided by 0")
else:
print(f'The value is {100/num}')

See the result…..


Happy
Learning!

You might also like