0% found this document useful (0 votes)
25 views18 pages

GR 7 Handout-Variables, Constant, Datatypes

Uploaded by

Sreehari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views18 pages

GR 7 Handout-Variables, Constant, Datatypes

Uploaded by

Sreehari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Constant

A constant is a data item whose value cannot change during the


program's execution.
Ex: PI=3.14
GRAVITY = 9.8
In Pseudocode, keywords are written in
uppercase, variables in lowercase and messages in
sentence case. INPUT asks a question. PRINT or
OUTPUT prints a message on screen.
Rules and Naming Convention for
Variables :

• Constant and variable names should have a


combination of letters in lowercase (a to z) or
uppercase (A to Z) or digits (0 to 9) or an underscore
(_).
• To create a variable name having two words, use
underscore to separate them.
• Preferably use capital letters to declare a constant.
• Never use special symbols like !, @, #, $, %, etc.
• Don’t start a variable name with a digit.
Question time
Which of the following
is the appropriate
variable or constant
name

•9studname
•stud_details
•car model
•%student
•employee@name
•PI
•GRAVITY
Data Types
Data Type is nothing but a categorization of data of different types. A data type
defines set of values along with operations that can be performed on those
values.
The following table shows data types with examples:

Types of data In Pseudocode In Python Examples


Integers INTEGER int 12, -999, 0, 900000, etc

Real Numbers REAL float 4.5, 0.0003, -90.5, 3.0; etc

Characters STRING str 'hello', "100", "$$$", ""; etc

Boolean BOOLEAN bool True , false


Any type of value can be assigned to any valid variable.
a=5
b = 3.2
c = "Hello"
https://www.101computing.net/data-types-quiz
HW

Basic programming
Worksheet 2
The pseudocode for an
assignment statement
 A value is assigned to an item/variable using the ¨ operator.
The variable on the left of the ¨ is assigned the value of the
expression on the right. The expression on the right can be a
single value or several values combined with any of the
following mathematical operators.
Mathematical Operators in pseudocode
Comparison operators in Pseudocode
Operators in Python
Arithmetic Operators: there are 7 arithmetic operator supported in python.

Op Operator Description Example Output


+ Addition Adds the operands >>>print(a+b) 300
- Subtraction Subtracts the operands >>>print(a-b) -100
* Multiplication Multiplies the operands >>>print(a*b) 20000
/ Division Divides operands gives the quotient >>>print(17/3) 5.666666666666667
and result is always float. >>>print(12/5.0) 2.4
>>>print(9/4) 2.25
% Modulo or Remainder after division >>>print(5%3) 2
Remainder >>>print(5.0%3) 2.0
>>>print(5.5%3) 2.5
// Floor Division After division quotient is adjusted >>>print(13//5) 2
to the integer less than or equal to >>>print(13.0//5.0) 2.0
result. For float division it returns >>>print(-19//5) -4
result in float. and for integer >>>print(-20/3.0) -7.0
operands it return integer output.

** Exponential or It returns X y where x, y are >>>print(10**3) 103=1000


power operands >>>print(10**-2) 10-2=0.01

Note : let a= 100 and b=200 for the above examples


Equality & Relational Operators : relational operators also called comparison operators are used to
compare two operands and determine the relation between them. Always return Boolean result.

Op Operator Description Examples Output


== Equality Return True if two operands are exactly equal. >>>10==True False
Compatible types are compared if we have same >>>False==False True
value, it returns True. >>>’lbrce’==’lbrce’ True
>>>10==20==30 False
>>>10==5+5==3+7 True
>>>’a’==97 False
>>>(10+2j)== (10+2j) True
>>>10==10.0 True
>>>1==True True

!= Not Equal Return True if two operands are not equal. >>>print(a!=b) True

> Greater than Return True if ‘a’ is more than ‘b’ where ‘a’ is >>>print(a>b) False
left and ‘b’ is right operand.

< Less than Return True if ‘a’ is less than ‘b’ where ‘a’ is left >>>print(a<b) True
and ‘b’ is right operands.

>= Greater than or Return True if ‘a’ is more than or equal to ‘b’ >>>print(a>=b) False
equal to where ‘a’ is left and ‘b’ is right operands.

<= Less than or Return True if ‘a’ is less than or equal to ‘b’ >>>print(a<=b) True
equal to where ‘a’ is left and ‘b’ is right operands.

Note : a=10 , b=20 for the above table


HW : complete the notes .

Basic Programming Worksheet 3

You might also like