0% found this document useful (0 votes)
48 views

Pyton Notes

The document provides instructions on basic Python programming concepts like variables, data types, operators, and input/output. It explains how to define and assign values to variables, perform arithmetic operations and take user input. Code snippets are included to demonstrate printing output, taking input, and using variables, operators, and data types in simple Python programs.

Uploaded by

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

Pyton Notes

The document provides instructions on basic Python programming concepts like variables, data types, operators, and input/output. It explains how to define and assign values to variables, perform arithmetic operations and take user input. Code snippets are included to demonstrate printing output, taking input, and using variables, operators, and data types in simple Python programs.

Uploaded by

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

PYTHON

Snake
AIM: Be able to run a basic programs in Python
independently.
Learning Outcome
1. Know programming mode in Python and how to debug simple
syntax errors.

2. Identify what variables are within Python code.

3. Explain the use of print() and what happens when programs


run.
Python Mode
Interactive Mode: Interactive mode is a command line shell which gives immediate
result for each statement and make it easy to test code snippets before incorporating
them in to large programs.
The >>> is called Python prompt which indicate that you are in interactive mode.

Script Mode: Script allows us to write a set of statements or a complete program


in python. In this mode , a set of statements or a program is stored in a file
with .py extension.

IDLE: It is a graphical “ Integrated Development Environment” for


Python. It contains a Python shell program that let you type instructions into
the computer.
Python Prompt: The Python prompt “>>>” is displayed by the interpreter which
indicates that it is ready to take input by the user.
Python Statement

Assignment Conditional Looping


print statements, statements statements statements.

l=10 If
X=20 for loop
Print(x) print('Hello’) B=20 condition:
while..
20 Hello
RECAP
Class discussion – Syntax errors

1. >>> print"Hello World"


2. >>> print("Hello World");
3. >>> Print("Hello World")
4. >>> print("Hel World")
5. >>> prin(Hello World)
RECAP
PRINT COMMAND
Type out your own Print Commands asking questions such as

• What is today’s day?



• Where are you from?

• What are you looking forward to this weekend?
a=10
b=20
c=15
sum=a+b+c
avg=sum/3
print(sum,avg)
Variables Coding is like
cooking and
variables are
like containers..
What do you think a variable means?
In programming, a “variable” is a container which a
data value can be stored within a computer’s memory.

Variables are
containers for
storing data
values.
Rules For Writing Variables
•A variable name must start with a letter or the underscore

character

•A variable name cannot start with a number

•A variable name can only contain alpha-numeric characters and

underscores (A-z, 0-9, and _ )

•Variable names are case-sensitive (age, Age and AGE are


Identify the correct variable names

1. $mark
2. Mark1
3. 1name
4. _salary
5. average
6. AVERAGE
7. Average
Write your very first python program and create
some variables.
# find the area of a rectangle
l=5
b=8
area=l*b
print(area)
TYPES OF VARIABLES
There are different types of variables –
• Numeric Variable
eg. x, mark,average,total,hra

• string Variable eg.


eg. “Arjun”, “Welcome to Dubai”, “23A”, “+971-50-321345
Numeric Type- Eg. x=10.
An object of Number data type represents a numeric literalcx. In computer
science, a literal is a notation for representing a fixed value in the source code.
For example, in the assignment statement: x=10

Python identifies three numeric types.


Integer:
Zero, positive and negative whole numbers without a fractional part and having unlimited precision, e.g. 1234, 0, -

Float:
Positive and negative real numbers with a fractional part denoted by the decimal symbol or the
scientific notation using E or e, e.g. 1234.56, 3.142, -1.55, 0.23.

Complex:
A complex number is a number with real and imaginary components. For example, 5 + 6j is a
complex number where 5 is the real component and 6 multiplied by j is an imaginary component.
Examples: 1+2j, 10-5.5J, 5.55+2.33j, 3.11e-6+4j
Type the following commands in Python prompt
and find out the results.
>>>x=5
>>>y=10
>>>x+y
>>>p=x+y
>>>print(p)
What will be the
output of the following Python Statements
m1=20
m2=25 Output
M3=30
Tot=m1+m2+m3 _________
avg=tot/3
Print(tot,avg)

>>>print(4*”hello”) >>>_______
Employing variables in Python

Assigning a value
Type var=8
Type print(var)
Next, assign a new value and display that stored value.
Type var=‘Python is easy’
Type print(var)
What happened?
Can you explain what happened when you assigned a value in Python?
Error Analysis

a=10;
b=20
c=15
sum=a+b+c:
avg=sum/3
print(sum,average)
Python - String
A string object is one of the sequence data types in Python.

It is an immutable sequence of Unicode characters. Strings are


objects of Python's built-in class 'str'. String literals are written by
enclosing a sequence of characters in single quotes ('hello'), double
quotes ("hello") or triple quotes ('''hello''' or """hello""").
Write a Python program to find the sum of
two numbers

num1=input("Enter the first number")


num2=input("Enter the second Number")
sum=float(num1)+float(num2)
print("sum of Num1 and num2=",sum)
Q2.Write a Python program to find the product of two
numbers

Q3.Write a Python program to divide two numbers.


Python Data Types
Data types are the classification or categorization of data items.
Data types represent a kind of value which determines what
operations can be performed on that data. Numeric, non-numeric
and Boolean (true/false) data are the most used data types.
Python has the following standard or built-in data
types:

Numeric
A numeric value is any representation of data which has a
numeric value. Python identifies three types of numbers:
•Integer: Positive or negative whole numbers (without a
fractional part)
•Float: Any real number with a floating point representation in
which a fractional component is denoted by a decimal symbol
or scientific notation
•Complex number: A number with a real and imaginary
component represented as x+yj. x and y are floats and j is -
1(square root of -1 called an imaginary number)
Operator Description Example
+ Addition a + b will give 30
– Subtraction b will give -10
* Multiplication a * b will give 200
/ Division b / a will give 2
% Modulus b % a will give 0
** Exponent a**b will give 10 to the power 20
// Floor Division 9//2 is equal to 4 and 9.0//2.0 is equal to 4.0
Comparison Operators

The basic comparison operators such as ==, <, >=, and so forth are
used on all manner of values.

Operator Description
< less than
<= less than or equal
== equal
> greater than
>= greater than or equal
!= not equal
<> not equal
Logical Operators

The logical operators and and or also return a Boolean value when
used in a decision structure.
There are three logical operators: and, or, and not.
For example, x > 0 and x < 10 is true only if x is greater than 0 and
less than 10
Operator Description
and logical AND
or logical OR
not logical NOT
input(prompt) to accept input from a user.

name = input("Enter Employee Name")


salary = input("Enter salary")
company = input ("Enter Company name")
print("Printing Employee Details")
print ("Name", "Salary", "Company")
print (name, salary, company)

You might also like