Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Programming concepts

In this chapter you will learn about:


• programming  how to use:
 declaration and use of: • sequence
• variables
• selection
• constants
 basic data types: • repetition
• integer • totaling
• real • counting
• char
• string
• use of predefined procedures/functions
• Boolean
Programming
HOW TO PUT YOUR COMPUTATIONAL THINKING TO THE ULTIMATE TEST BY
WRITING COMPUTER PROGRAMS TO PERFORM TASKS.

FOR THAT WE ARE USING SOME PROGRAMMING LANGUAGES THAT CAN BE


UNDERSTAND BY THE MACHINE,
ONLY WHEN IT IS CONVERTED INTO MACHINE LANGUAGES.
Classification of datatypes
Declaration and use of variables and
constants
# VARIABLES
IN PROGRAMMING, VARIABLES OR MEMORY LOCATIONS SHOULD BE
DECLARED BEFORE IT CAN BE USED.

# CONSTANT

A CONSTANT IN A COMPUTER PROGRAM IS A NAMED DATA STORE THAT CONTAINS A


VALUE THAT DOES NOT CHANGE DURING THE EXECUTION OF THE PROGRAM. IN
ORDER TO MAKE PROGRAMS UNDERSTANDABLE TO OTHERS, CONSTANTS SHOULD
BE GIVEN MEANINGFUL NAMES.
basic data types
Data types simply refers to the type and size of data associated with variables

Integer
Integers are whole numbers that can have both positive and negative
values but no decimal values.
Example: 0, -5, 10.

Float

Floating type variables can hold real numbers such as: 2.34, -9.382, 5.0
etc
Ex: FirstInteger = int(25) & FirstReal = float(25.5)
Char
Keyword char is used for declaring character type variables. For example:
char test = 'h';
Here, test is a character variable. The value of test is 'h'.
The size of character variable is 1 byte
String
A sting is a group of characters. Strings vary in length and may even have no characters: an empty
string. The characters can be letters and/or digits and/or any other printable symbol.

Ex: FirstName = 'Emma'


symbols= '@!&&565@@##!'

Boolean
BOOLEAN variable can have only two values: TRUE or FALSE.
Computer
Programs
r = float(input('Enter radius of the cylinder: '))
h = float(input('Enter the height of the cylinder: '))
Vol = float (0)
Pi = 3.14
Vol = Pi*r*r*h
Print(“the volume of the cylinder is:”,Vol)
Python program to add two numbers

Firstnumber = int (0)


Secondnumber = int (0)
Sum = int (0)
Firstnumber = int (input(“Enter the first number:”))
Secondnumber = int (input(“Enter the second Number:”))
Sum = firstnumber = secondnumber
Print (“the sum is”,sum)
Python program showing selection

firstnumber = int (0)


secondnumber = int(0)
firstnumber = int(input("Enter the first number"))
secondnumber = int(input("Enter the second number"))
if firstnumber > secondnumber:
print ("The largest number is",firstnumber)
else:
print ("The largest number is",secondnumber)
Python repetition program

number = int (0)


count = int (0)
sum = int (0)
while count < 5:
number = int(input("Enter a whole number: "))
sum = sum + number
count = count + 1
print ("sum of five number is", sum)

You might also like