Computing-
1.5-
Data types-
Integer- whole number
real- Decimal number
character- one letter, number or symbol
string- One or more letters ,numbers and symbols
Boolean- true or false.
A Boolean data type does not need quotation marks around it. With no quotation
marks, the words true or false are considered as Boolean data, with quotation
marks, the words are considered as string. In pseudo code the words true and false
can al be lowercase letters, al uppercase letters or just the first letter can be
uppercase. Some programming languages use 1 and 0 instead of true and false. In
python Boolean values must start with a capital letter.
Flags use Boolean data. Flags are conditions that can be true or false. These are
useful as you can determine if a condition is true or false, and then later on if
you need it again instead of determining the condition again, you can just use the
flag. You can also store flags in a variable.
A constant is similar to a variable, it is data stored in a variable that can be
accessed but not changed later in the program.
Constants are declared at the start of a program.
it has four parts, a keyword (like constant), an identifier (the variable), an
assignment value (=) and the value.
eg: constant ten = 10. We can show that we want a variable to be used as a constant
by using all uppercase letters.
In pseudocode we can write it as constant identifier = value
In python we write it as IDENTIFIER = value
In a flowchart it is constant identifier = value
Questions:
1- what are the two values that can be stored in a Boolean data type
2- What is the difference between the data "True" and True
3 Identify the data type that must be used for each of these:
a - "Film"
b - 33.4
c - -1999
d - False
1.6
There are two types of subroutine: functions and procedures.
A function is one that returns a value, as in sending a value back to the function
that called it.
Here is the pseudocode to call it:
Code
Call function
Identifier
Function Identifier
code
Tell main program
Python: def functionname ():
code in function
To print things in a function we must right return "say wtv"
then in the main program we must print(myFunction())
def second ():
color = input("give color")
return color
this function prints the data in color.
Subroutines that don't return values are procedures. They follow a series of
instructions but do not need to send anything back to the main program. In python
all subroutines are called functions. We dont need to know the difference.
Some subroutines take parameters. A parameter is a value sent to a subroutine when
its called. For example a subroutine calculates area of square, the length of the
side would be a parameter.
eg code: length = int(input('enter length'))
area = squareArea(length)
print("the area is" , area)
A program library is a collection of subroutines already available for your use.
Some algorithims are frequently used by programmers, hence instead of everyone
having to rewrite the code, you can use a library program to do it. The library
math has a function to give the value of pi.
To use a program library you need to import it into your program.
Benefits: Helpful as its faster, Reliable
Cons: May have certain things missing, may be malware.
To use library in python we need to use the command import and the name of the
library.
eg of libraries: math, random, pandas
math library functions: floor ceiling pi
first we need to write import math at the top of our program.
floor() rounds a number down to the nearest whole number. The syntax for this is
[Link](number)
ceil() rounds a number to the next whole number. [Link](number).
[Link] uses the value of pi.
random library:
import random has to be written first
randint() will enter a whole number between two numbers you enter as parameters.
The parameters must be whole numbers.
the syntax for calling this is [Link](smallest, largest)
Questions:
What is a program library
What are program libraries used for
Why do we have to be careful when using libraries
What is the command in python to import a library into your program
What is the function call to round down the number 44.56
what does [Link]() do
What will print([Link](9999.9999)) and print ([Link](9999.9999)) output?