Python Module1 Notes
Python Module1 Notes
MODULE 1
Prepared By: Prof. Keerthi R
Dept. of CSE(AI&ML)
DBIT Bengaluru
DBIT 1|Page
Conversing with Python
To converse with Python, the Python software must first be installed. Once installed,
Python can be started from the terminal or command prompt by typing python. This
opens the Python interpreter in interactive mode, where the prompt >>> appears. The
prompt is Python’s way of asking: “What do you want me to do next?”
• If the user types plain English sentences, Python cannot understand and produces a
Syntax Error.
• If the user types valid Python syntax such as the print() function, Python executes
the command and displays the result.
• Even a small mistake in syntax (missing parentheses, wrong quotes, etc.) will
generate errors, showing that Python is strict with syntax rules.
• Python itself is not intelligent; it only follows the rules of its language. The
“conversation” is actually between the programmer and the computer, with Python
acting as the medium.
• To exit the interpreter, the command quit() is used.
Python provides two ways of writing and running programs:
1. Interactive Mode
• In this mode, Python runs one command at a time.
• We type a command at the >>> prompt, and Python immediately gives the result.
• It feels like having a conversation with the computer.
Example:
>>> 2 + 3
5
>>> print("Hello, Python!")
DBIT 2|Page
Hello, Python!
2. Script Mode
• In this mode, we write the program in a file with .py extension.
• The whole program runs when we execute the file.
• This is used for longer programs.
Example ([Link]):
print("Welcome to Python")
a=5
b=7
print("Sum:", a + b)
Output:
Welcome to Python
Sum: 12
(Conversing with Python means interacting with the Python interpreter either in
interactive mode or in script mode ,where the programmer gives input and Python
responds with output.)
What is a program?
A program is a sequence of instructions written by a programmer to perform a specific
task using a computer.
• It takes input, processes it, and produces output.
• Programs help us solve problems, automate tasks, and perform calculations.
Example:
num = int (input ("Enter a number: ")) # Input from the user
square = num * num #Calculate square
print ("Square of", num, "is", square) # Display the result
DBIT 3|Page
Interpreter and Compiler
Python is a high-level programming language designed to be easy for humans to read,
write, and understand. high-level languages include Java, C++, PHP, Ruby, Perl, and
JavaScript. However, the CPU cannot understand high-level languages directly—it only
understands machine language, which is written in binary (0s and 1s).
Since writing programs directly in machine language is very difficult for humans,
programs written in high-level languages are translated into machine code using either a
compiler or an interpreter, so the CPU can execute them.
Interpreter
• An interpreter is a program that executes code line by line.
• It reads one instruction, translates it into machine language, and runs it
immediately.
• If there is an error in a line, the interpreter stops at that line and shows the error.
• Ex: Python, PHP, JavaScript
Compiler
• Translates the entire program into machine code at once.
• After compilation, the program can run many times without recompiling.
• Errors are shown after the whole program is compiled.
• Faster than an interpreter for large programs.
• Ex: C, C++
DBIT 4|Page
Ex:
print("Hello,", name)
[Link]
A variable is a named memory location used to store data that can be used and
modified in a program.
Ex:
x = 10
name = "Spam"
price = 25.5
4. Values
A value is the data/information stored in a variable
Ex: x = 10
Here 10 is a value stored under the variable ‘x’
5. Datatypes
A data type is the classification of data that tells the computer what type of value
a variable holds.
Ex:
Int type: a=10
Float type: a=10.5
String type: fruit_name=”mango”
Boolean type: pass=True
6. Sequential Execution
• By default, the computer executes statements one after another in order.
• This is called sequential execution.
Ex:
x=5
y = 10
print(x + y) # runs after the first two lines
7. Conditional Execution
• Sometimes we want the program to make decisions.
DBIT 5|Page
• Using conditions (if, else), the program decides which statements to execute.
Ex:
age = 18
if age >= 18:
print("You can vote")
else:
print("You cannot vote")
8. Repeated Execution (Loops)
• Perform some set of statements repeatedly.
• We use loops (for, while) to run statements multiple times.
Ex:
for i in range(3):
print("Hello")
Output:
Hello
Hello
Hello
9. Reuse (Functions)
Instead of writing the same code many times, we can write it once as a function
and use it whenever needed.
Ex:
def greet():
print("Welcome to Python!")
greet() # function reused
greet()
Output:
Welcome to Python!
Welcome to Python!
What could possibly go wrong?
DBIT 6|Page
When writing programs, mistakes are very common. These mistakes are called
errors (bugs), and they prevent the program from working correctly.
There are mainly three types of errors:
1. Syntax Errors
A syntax error happens when your code breaks the rules of Python’s language, just
like using wrong grammar in English. Python can’t understand your code if there is a
syntax error, so it stops running and shows an error message. Sometimes Python tells you
the exact line where the mistake is, but the real problem could be a few lines before that.
You need to fix syntax errors before your program can run.
Ex:
print("Hello" # missing closing parenthesis
Error:
SyntaxError: unexpected EOF while parsing
2. Semantic Errors is when your description of the steps to take is
syntactically perfect and in the right order, but there is simply a mistake in
the program. The program is perfectly correct but it does not do what you
intended for it to do.
Eg: To calculate average of two numbers
a = 10
b = 20
print("Average =", a + b / 2) # Wrong logic
Output:
Average = 20 # Incorrect result
----→ should be ( a + b ) /2=15
3. Logical Errors
A logic error is when your program has good syntax but there is
a mistake in the order of the statements or perhaps a mistake in how the
statements relate to one another.
Ex: : Find the largest of two numbers
DBIT 7|Page
a = 10
b = 20
if a < b: #comparing incorrectly
largest = a
else:
largest = b
print ("Largest number is:", largest)
• A value is a basic piece of data a program works with, such as a number or a letter.
• Examples: 1, 2, "Hello, World!"
DBIT 8|Page
These values belong to different types: 2 is an integer, and “Hello, World!” is a
string, so called because it contains a “string” of letters. You (and the interpreter)
can identify strings because they are enclosed in quotation (“ “) marks.
A type in Python tells the kind of value a variable hold. Python has several built-in
types, and the most common ones are:
1. Integer (int)
• Represents whole numbers without decimal points.
• Examples: 10, -5, 0
• Can be used in arithmetic operations:
a = 10
b=3
print(a + b) # Output: 13
2. Floating-point (float)
• Represents numbers with decimal points.
• Examples: 3.14, 0.5, -2.7
• Useful for precise calculations:
x = 3.2
y = 1.8
print(x + y) # Output: 5.0
3. String (str)
• Represents text or sequence of characters.
• Always enclosed in single or double quotes.
• Examples: "Hello", 'Python', "17"
• Strings can be printed, concatenated, and sliced:
name = "Python"
print(name) # Output: Python
print("Hello " + name) # Output: Hello Python
DBIT 9|Page
4. Boolean (bool)
• Represents True or False values.
• Often used in conditions and comparisons:
a=5
b=3
print(a > b) # Output: True
Variables
A variable is like a box in the computer’s memory where we can store a single value. If
we want to use the result of an evaluated expression later in our program, we can save it
inside a variable.
• This example makes three assignments. The first assigns a string to a new variable
named message;
• the second assigns the integer 17 to n;
DBIT 10 | P a g e
• the third assigns the (approximate) value of ℿ to pi.
To display the value of a variable, you can use a print statement:
>>> print(n)
17
>>> print(pi)
3.141592653589793
The type of a variable is the type of the value it refers to.
>>> type(message)
<class 'str'>
>>> type(n)
<class 'int'>
>>> type(pi)
<class 'float'>
Variable names
Programmers generally choose names for their variables that are meaningful and
document what the variable is used for.
A variable name can be as long as needed and can contain both letters and digits, but it
must follow certain rules.
DBIT 11 | P a g e
Keywords
In Python, keywords are special reserved words that have predefined meanings. The
interpreter uses keywords to recognize the structure of the program, and they cannot be
used as variable names.
Statements
A statement is a unit of code that the Python interpreter can execute. Python programs
are made up of a sequence of statements.
Types of Statements
1. Expression Statement
• Example: print (1+5)
• Executes an expression and displays the result.
2. Assignment Statement
• Example: x = 2
• Assigns a value to a variable.
Execution in Interactive Mode
• When a statement is typed in interactive mode (Python shell), the interpreter
executes it immediately and shows the result.
Example:
>>> print(5 + 3)
8 #output
>>> x = 10
DBIT 12 | P a g e
>>> x * 2
20 #output
Execution in Script Mode
• Each statement is executed in order, and results (if any) are displayed one by one.
Example:
print(1)
x=2
print(x)
Expressions
DBIT 13 | P a g e
Operators and operands
Operators are special symbols that represent computations like addition and
multiplication. The values the operator is applied to are called operands.
DBIT 14 | P a g e
Use // to perform integer (floored) division in Python 3.
minute = 59
minute // 60 # Output: 0
Order of operations
When more than one operator appears in an expression, Python decides the order of
evaluation using rules of precedence, which are the same as in mathematics. The acronym
PEMDAS helps to remember this order:
Rules of Precedence:
1. Parentheses ( ) – evaluated first.
Example: 2 * (3 - 1) → 4
2. Exponentiation ( )** – evaluated next.
Example: (1 + 1) ** (5 - 2) → 8
3. Multiplication (*), Division (/), Floor Division (//), and Modulus (%) – same
precedence, evaluated left to right.
Example: 6 + 4 / 2 → 8.0 (division happens first).
4. Addition (+) and Subtraction (-) – same precedence, evaluated left to right.
Example: 5 - 3 - 1 → 1 (first 5 - 3 = 2, then 2 - 1 = 1).
Example:
>>> 2 + 3 * 6
20
>>> (2 + 3) * 6
30
>>> 2 ** 8
256
>>> 23 / 7
3.2857142857142856
>>> 23 // 7
3
>>> 23 % 7
2
>>> (5 - 1) * ((7 + 1) / (3 - 1))
4 * (8 / 2)
4*4
16.0
DBIT 15 | P a g e
>>> (5+3) ** 2/ 4
8 ** 2/4
64 / 4 (Note: 8 ** 2= 8*8 = 64)
16
Modulus operator
The modulus operator works on integers and yields the remainder when the first
operand is divided by the second. In Python, the modulus operator is a percent
sign (%). The syntax is the same as for other operators:
>>> quotient = 7 // 3
>>> print(quotient)
2
>>> remainder = 7 % 3
>>> print(remainder)
1
So 7 divided by 3 is 2 with 1 left over.
The modulus operator turns out to be surprisingly useful. For example, you can
check whether one number is divisible by another: if x % y is zero, then x is
divisible by y.
You can also extract the right-most digit or digits from a number. For example,
x % 10 yields the right-most digit of x (in base 10).
Similarly, x % 100 yields the last two digits.
Example: x=1234
x % 10 = 1234 % 10 = 4 (last digit of x i.e., 1234)
x % 100 = 1234 % 100 = 34 (last 2 digit of x i.e.,1234)
String operations
The + operator works with strings, but it is not addition in the mathematical sense.
Instead it performs concatenation, which means joining the strings by linking them
end to end. For example:
>>> first = 10
>>> second = 15
DBIT 16 | P a g e
>>> print(first+second)
25
>>> first = '100'
>>> second = '150'
>>> print(first + second)
100150 (Note: ‘100’ and ‘150’ are treated as string)
The * operator also works with strings by multiplying the content of a string by
an integer, it is called as String Replication. For example:
>>> first = 'Test '
>>> second = 3
>>> print(first * second)
Test Test Test
Asking the user for input
• Sometimes we would like to take the value for a variable from the user via their
keyboard.
• Python provides a built-in function called input() that gets input from the
keyboard.
• When input function is called, the program stops and waits for the user to type
something.
• When the user presses Return or Enter, the program resumes and input returns
what the user typed as a string.
>>> inp = input()
Some silly stuff # Suppose the user types ‘Some silly stuff ’.
>>> print(inp) # The value stored in the variable ‘inp’ got printed.
Some silly stuff
• Before getting input from the user, it is a good idea to print a prompt telling the
user what to input. You can pass a string to input to be displayed to the user
before pausing for input:
>>> name = input ('What is your name ?\n')
What is your name?
Chuck
>>> print(name)
Chuck
• The sequence \n at the end of the prompt represents a newline, which is a special
DBIT 17 | P a g e
character that causes a line break. That’s why the user’s input appears below the
prompt.
• input() always gives strings.
• If you want a number, you must convert it using int() or float().
>>> prompt = 'What...is the airspeed velocity of an unladen swallow?\n'
>>> speed = input(prompt)
Output:
What...is the airspeed velocity of an unladen swallow?
17 # user enter 17
>>> int(speed)
17
>>> int(speed) + 5
22
• If the user types letters or symbols instead of digits, int() or float() will fail.
• This gives a ValueError.
Example:
speed = input("Enter speed: ")
hello # user inputs
int(speed)
Output:
Error: ValueError: invalid literal for int() with base 10: 'hello'
Comments
• Comments are notes written inside the code to explain what the code is doing.
• They are not executed by the Python interpreter.
• They are used to make the code easier to read and understand.
• Comments start with the # symbol.
• Everything after # on that line is ignored by Python.
Example:
percentage = (minute * 100) / 60 # percentage of an hour
v = 5 # assign 5 to v
DBIT 18 | P a g e
words, you have a lot of choice when you name your variables. In the beginning,
this choice can be confusing both when you read a program and when you write
your own programs.
Example 1:
a = 35.0
b = 12.50
c=a*b
print(c)
Example 2:
hours = 35.0
rate = 12.50
pay = hours * rate
print(pay)
• Two above programs are same for Python but easier for humans to understand
second one.
• Meaningful variable names are called mnemonic variable names (mnemonic
means memory aid).
• Mnemonic variable names help remember purpose of variables.
• Beginners may confuse descriptive variable names as reserved words.
Python has only 35 reserved words.
• Take a quick look at the following Python sample code which loops through some
data.
for word in words:
print(word)
The following code is equivalent to the above code:
for slice in pizza:
print(slice)
It is easier for the beginning programmer to look at this code and know which parts
are reserved words defined by Python and which parts are simply variable names
chosen by the programmer. It is pretty clear that Python has no fundamental
understanding of pizza and slices and the fact that a pizza consists of a set of one
DBIT 19 | P a g e
or more slices.
• pizza and slice are very un-mnemonic variable names. Choosing them as variable
names distracts from the meaning of the program
• Beginners can better distinguish reserved words in second loop.
• Mnemonic names improve meaning but may initially confuse beginners.
• With practice, reserved words (like for, in, print, :) become easy to recognize.
• Text editors highlight reserved words to help distinguish them from variables
• Syntax Errors
➢ Happen when you break the rules of Python’s grammar.
➢ Examples: using reserved keywords as variable names (class, yield) or
illegal characters (odd~job, US$).
➢ Spaces in variable names cause errors:
➢ bad name = 5 # SyntaxError: invalid syntax
➢ Error message usually shows: SyntaxError: invalid syntax.
• Runtime Errors
➢ Occur while the program is running.
➢ Most common is using a variable before defining it (use before def):
➢ principal = 327.68
➢ interest = principle * rate
➢ # NameError: name 'principle' is not defined
➢ Variables names are case sensitive, so LaTeX is not the same as latex
• .Semantic Errors
➢ Program runs but gives the wrong result.
➢ Usually caused by mistakes in logic or order of operations.
➢ Example:
➢ 1.0 / 2.0 * pi # gives pi/2 instead of 1/(2*pi)
➢ These errors don’t show error messages, just incorrect answers.
Boolean expressions
A boolean expression is an expression that is either true or false. The following
examples use the operator ==, which compares two operands and produces True if
they are equal and False otherwise:
DBIT 20 | P a g e
>>> 5 == 5
True
>>> 5 == 6
False
True and False are special values that belong to the type bool; they are not
strings:
>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>
The == operator is one of the comparison operators; the others are:
x != y # x is not equal to y
x > y # x is greater than y
x < y # x is less than y
x >= y # x is greater than or equal to y
x <= y # x is less than or equal to y
x is y # x is the same as y
x is not y # x is not the same as y
Although these operations are probably familiar to you, the Python symbols are
different from the mathematical symbols for the same operations.
• A common error is to use a single equal sign (=) instead of a double equal sign
(==).
• Remember that = is an assignment operator and == is a comparison operator.
There is no such thing as =< or =>.
Logical operators
There are three logical operators: and, or, and not. The semantics (meaning) of
these operators is similar to their meaning in English. For example,
x > 0 and x < 10
is true only if x is greater than 0 and less than 10.
n%2 == 0 or n%3 == 0 is true
if either of the conditions is true, that is, if the number is divisible by 2 or 3.
Finally, the not operator negates a boolean expression, so not (x > y) is true if
x > y is false.
DBIT 21 | P a g e
>>> x = 1
>>> y = 2
>>> x > y
False
>>> not (x > y)
True
Strictly speaking, the operands of the logical operators should be boolean expressions,
but Python is not very strict. Any nonzero number is interpreted as “true.”
This flexibility can be useful in some situations, but there are some subtleties to it
that might be confusing. You might want to avoid it until you are sure you know
what you are doing.
Conditional execution
Conditional statements are used to check conditions and change the behavior of a
program. The if statement is the simplest form of a conditional.
if x > 0 :
print('x is positive')
• The boolean expression after the if statement is called the condition. We end the if
statement with a colon character (:) and the line(s) after the if statement are
indented.
• If the logical condition is true, then the indented statement gets executed. If the
logical condition is false, the indented statement is skipped.
• if statements have the same structure as function definitions or for loops. The
statement consists of a header line that ends with the colon character (:) followed
DBIT 22 | P a g e
by an indented block. Statements like this are called compound statements because
they stretch across more than one line.
if x > y:
print(x) If Logic
print(y)
• There is no limit on the number of statements that can appear in the body, but
there must be at least one. Occasionally, it is useful to have a body with no
statements (usually as a place holder for code you haven’t written yet). In that
case, you can use the pass statement to pass the Python interpreter check, which
does nothing.
if x < 0 :
pass # need to handle negative values, do nothing for now.
• If you enter an if statement in the Python interpreter, the prompt will change
from three chevrons (»>) to three dots (. . . ) to indicate you are in the middle of
a block of statements, as shown below:
>>> x = 3
>>> if x < 10:
... print('Small')
...
Small
>>>
When using the Python interpreter, you must leave a blank line at the end of a
block, otherwise Python will return an error:
>>> x = 3
>>> if x < 10:
DBIT 23 | P a g e
... print('Small')
... print('Done')
File "<stdin>", line 3
print('Done')
ˆ
SyntaxError: invalid syntax
A blank line at the end of a block of statements is not necessary when writing and
executing a script, but it may improve readability of your code.
Alternative execution
A second form of the if statement is alternative execution, in which there are two
possibilities and the condition determines which one gets executed. The example
looks like this:
if x % 2 == 0:
print('x is even')
else:
print('x is odd')
If the remainder when x is divided by 2 is 0, then we know that x is even, and the
program displays a message to that effect. If the condition is false, the second set
of statements is executed.
Since the condition must either be true or false, exactly one of the alternatives will
DBIT 24 | P a g e
be executed. The alternatives are called branches, because they are branches in
the flow of execution.
Chained conditionals
A chained conditional is a conditional statement that uses multiple conditions with if,
elif, and else to allow a program to choose one out of several possible branches to
execute.
if x < y:
print('x is less than y')
elif x > y:
print('x is greater than y')
else:
print('x and y are equal')
• elif is an abbreviation of “else if.” Again, exactly one branch will be executed.
• There is no limit on the number of elif statements. If there is an else clause, it has
to be at the end, but there doesn’t have to be one.
if choice == 'a':
print('Bad guess')
elif choice == 'b':
print('Good guess')
DBIT 25 | P a g e
elif choice == 'c':
print('Close, but not correct')
Each condition is checked in order. If the first is false, the next is checked, and so
on. If one of them is true, the corresponding branch executes, and the statement
ends. Even if more than one condition is true, only the first true branch executes.
Nested conditionals
Nested conditionals are if statements inside another if (or else) block.
They are used when you need to check a second condition only if the first condition is
true.
Example:
if x == y:
print('x and y are equal')
else:
if x < y:
print('x is less than y')
else:
print('x is greater than y')
In this example, the program first checks if x and y are equal. If they are, it prints a
message.
If not, it goes to the else part, which has another if to check if x is less than y; if true, it
prints that x is less, otherwise it prints that x is greater.
This way, one condition is checked only if the previous condition is not true.
DBIT 26 | P a g e
if 0 < x:
if x < 10:
print('x is a positive single-digit number.')
The print statement is executed only when we pass both conditionals. We can
get the same effect with the and operator:
if 0 < x and x < 10:
print('x is a positive single-digit number.')
Logical operators often provide a way to simplify nested conditional statements.
For example, we can rewrite the following code using a single conditional:
if 0 < x:
if x < 10:
print('x is a positive single-digit number.')
The print statement is executed only when we pass both conditionals. We can
get the same effect with the and operator:
if 0 < x and x < 10:
print('x is a positive single-digit number.')
DBIT 27 | P a g e
Output 1:
python [Link] #python file is saved as .py extension, running in interactive mode i.e.,
in command prompt
Enter Fahrenheit Temperature:72
22.22222222222222 #correct Output
Output 2:
python [Link]
Enter Fahrenheit Temperature: fred #Giving Wrong Input
Traceback (most recent call last):
File "[Link]", line 2, in <module>
fahr = float(inp)
ValueError: could not convert string to float: 'fred'
To avoid this error, Python provides a way to handle errors safely using try and except.
This is called exception handling. You use a try block to write the code that might cause
an error, and an except block to write the code that should run if an error happens. If
there is no error, the except part is skipped. If an error occurs, the program immediately
jumps to the except block and continues running from there. This helps your program to
continue running or show a friendly message instead of crashing.
You can think of the try and except feature in Python as an “insurance policy”
on a sequence of statements.
We can rewrite our temperature converter as follows:
inp = input('Enter Fahrenheit Temperature:')
try:
fahr = float(inp)
cel = (fahr - 32.0) * 5.0 / 9.0
print(cel)
except:
print('Please enter a number')
# Code: [Link]
DBIT 28 | P a g e
Short-circuit evaluation of logical expressions
When Python is processing a logical expression such as x >= 2 and (x/y) > 2, it
evaluates the expression from left to right. Because of the definition of and, if x is
less than 2, the expression x >= 2 is False and so the whole expression is False
regardless of whether (x/y) > 2 evaluates to True or False.
When Python detects that there is nothing to be gained by evaluating the rest
of a logical expression, it stops its evaluation and does not do the computations
in the rest of the logical expression. When the evaluation of a logical expression
stops because the overall value is already known, it is called short-circuiting the
evaluation.
While this may seem like a fine point, the short-circuit behavior leads to a clever
technique called the guardian pattern. Consider the following code sequence in the
Python interpreter:
>>> x = 6
>>> y = 2
>>> x >= 2 and (x/y) > 2
True #Output
>>> x = 1
>>> y = 0
>>> x >= 2 and (x/y) > 2
False #Output
>>> x = 6
>>> y = 0
>>> x >= 2 and (x/y) > 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero #Error
DBIT 29 | P a g e
• In the first example, y was non-zero, so no error occurred.
• In the second example, x >= 2 was False, so due to short-circuiting, (x/y) was not
evaluated, and no error occurred.
• In the third example, x >= 2 was True and y was zero, so (x/y) was evaluated,
causing a runtime error.
We can construct the logical expression to strategically place a guard evaluation
just before the evaluation that might cause an error as follows:
>>> x = 1
>>> y = 0
>>> x >= 2 and y != 0 and (x/y) > 2
False
>>> x = 6
>>> y = 0
>>> x >= 2 and y != 0 and (x/y) > 2
False
>>> x >= 2 and (x/y) > 2 and y != 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
• In the first expression, x >= 2 is False, so evaluation stops immediately.
• In the second expression, x >= 2 is True but y != 0 is False, so (x/y) is never
evaluated, y != 0 works as a guard to ensure (x/y) runs only if y is non-zero.
• In the third expression, y != 0 comes after (x/y), so (x/y) is evaluated first and
causes an error.
Debugging (Logic Errors and Runtime Errors — especially wrong conditions and
division by zero)
The traceback Python displays when an error occurs contains a lot of information,
but it can be overwhelming. The most useful parts are usually:
• What kind of error it was, and
• Where it occurred.
Syntax errors are usually easy to find, but:
DBIT 30 | P a g e
• Whitespace errors (like extra spaces or tabs) can be tricky because they are
invisible.
• The error message might point to where the error was noticed, not where it
actually started.
Example:
x=5
y = 6 # has one extra space at the beginning
File "<stdin>", line 1 #Error
y=6
IndentationError: unexpected indent
• Even though the error message points to y, the real problem is the extra space
(indent) before it.
• Error messages show where Python detected the problem, but the actual cause
might be earlier in the code, sometimes even on a previous line.
DBIT 31 | P a g e