Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Computer Science

Introduction to problem solving - First step for problem solving is analyse the problem, when
analysing try and solve the problem in normal english and write it somewhere, now that is
called the algorithm. Algorithm is a basic way to demonstrate how to solve problems and the
algorithm is used to then make pseudo-codes. After the pseudo-code is made the same code is
run and tested if any errors occur we debug the code. Testing is a way to check if your
algorithm contains any problem. Debugging is to solve the problems occurring as it recognises
the problem present. Algorithm can also be written as a owchart.

Data Types - There are multiple data types (STRING, INTEGER, BOOLEAN, FLOAT, CHARACTER)
String - can take any value “a to z” “0 to 9”
Integer - can take any whole number “0 to 9”
Boolean - True/false or yes/no
Float - can take any irrational number. ex. 1.2
Character - can take any single character. ex. “a” , “b”

Operators - (+, -, *, /)

+ = addition operator
- = subtraction operator
* = multiplication operator
/ = division operator

the numbers that are being operated are called operands


ex. 1 + 5 = 6
here 1 and 5 are the operands and “+” is the operator

Errors - Syntax error or Logical error

Syntax error - The language you are writing your code in has a particular way of accepting the
lines of code you write. If that is not followed a syntax error is caused.
Example - Code accepts PRINT(“Hello World”) but you wrote PRINT(Hello World)
even one quotation mark can cause a syntax error

Logical error - This depends on the code you are writing.


Example - You want the sum of two numbers “a” and “b”
but the statement you wrote was a/b this is a logical error, as the answer will not come as
expected. It should be a+b.


fl

Iterative Statements - For Loop, While Loop, Repeat Until

For loop - it is a pre conditioned loop which means it takes the condition before starting the
iteration.
Syntax - for i in range(0,5):
print(“hey”)

While Loop - it is also a pre conditioned loop which means it takes the condition before starting
the iteration.
Syntax - while a > b:
print(“hey”)

Repeat Until - it is a post conditioned loop which means it takes the condition after doing one
iteration.
Syntax - Repeat:
print(“hey”)
Until a > b

Strings - it is a datatype
there are many operations that can be performed on a string value
len() this gives the number of characters in the string
lower() this converts the whole string to lower case
upper() this converts the whole string to upper case
endswith() this checks if the string is ending with the letter if true it displays true
startswith() this checks if the string is starting with the letter if true it displays true
lstrip() this removes the rst letter from the left side of the string
rstrip() this removes the last letter from the right side of the string
there are many more operations…

Lists - lists work basically as arrays in python


Syntax- abc[]
here abc is the name of the list and square brackets show that it is a list.
there are many operations that can be performed on lists too
len() this gives the number of values present inside a list
append() this helps to add values to the list
pop() this helps to remove a value from the list
sort() this sorts the list in ascending order by default
min() this returns the lowest index valued data ex. [5 , 2 , 7 , “a” , 3] it will return 5
max() this returns the highest index valued data ex. [5 , 2 , 7 , “a” , 3] it will return 3

Tuples - it acts like a list only but is not a list it basically is a variable that can store multiple
values
Syntax - abc()
here abc is the name of the list and the brackets show that it is a tuple
this also has operations that can be done but you can understand it by seeing the name
fi
Dictionary - abc = {}
here abc is the name of the dictionary and the curly brackets show that it is a dictionary.
The Dictionary data type is optimized for fast lookup of values. The following methods are
available on instances of the Dictionary data type. Adds the speci ed key and value to the
dictionary. Determines whether the Dictionary contains the speci ed key.

Example capitals = {"USA":"Washington D.C.", "France":"Paris", "India":"New Delhi"}

fi
fi

You might also like