Basics Of Programming Flashcards
What is Computer Science?
The study of computer software, algorithms and efficiency
Sequence of problem solving?
1) Understand the problem?
- What are the knowns and unknowns?
2) Plan how to solve the problem
- What algorithm is used to solve the problem
- What assumptions are being made?
- Is this similar to other problems?
- can the problem be split into parts?
3) Carry out your plan
- Write programs to implement algorithms?
4) Asses the result
- Does the program conform to the algorithm?
- Does the program/algorithm solve the problem?
- Is the program correct for the cases?
5) Describe what you have learnt
- So you do not make the same mistakes again
6) Document the solution
- Write a report for the uses of the program
- Write comments within the program
What is an algorithm?
Set of steps to accomplish a task
(Everyday tasks require algorithms i.e brushing teeth)
What characteristics must algorithms have?
Must be precise so:
- repeatable
- have a predictable outcome
- can be executed by different people
Elements of an algorithm
Sequence - Each step is followed by another step
Selection - a choice may be made among alternatives
Iteration - set of steps may be repeated
What is a program?
A set of instructions given to a computer, corresponding to an algorithm to solve a problem
How does a program work?
1) Ingest information from the real world
2) Process data internally
3) Send computed data back to real world
What is: - Print
- “Hello World”
An example of?
Print - Function
Hello world - Argument
What is a function?
A common task we can reuse
Syntax vs Logic error
Syntax - When the program doesn’t conform to the required structure
[ Print spelt incorrectly = PROGRAM WONT START ]
Logic - When the program runs but doesn’t work as expected
[ Must test it]
What does:
\a
\b
\n
\t
\’
\”
Produce?
- Bell
- Backspace
- Newline
- Tab
- Single Quote
- Double Quote
- Character
Integer vs Floating point
- Whole number with no fractional part = Integer
- Number with fractional part (not extremely precise) = Floating
How to do:
Addition
Subtraction
Division
Multiplication
Modulus
Integer Division
Power
What are they examples of?
/
*
% 5%2 =1
//
** a**b
Precedence of operators
( ) = High
* / % = Middle
+ - = Low
What is an identifier?
Used to name parts of code
(I.e print)
- Start with _ or letter, followed by more
- Prefered: hello_World or my_first_program
Reserved words: if, else, for
What are variables?
Sections of memory where data can be stored
I.e a_value = 10
What is a comment?
Part of code (Starting with #) that is ignored by python and intended to help a human reader
What is a string literal / j Eric literal?
Fixed character sequences [“Hello]
Numbers used directly [3.15]
What is syntax?
The fundamental rules of a programming language
Wayne Napolo
Identify:
from math import sqrt
Side1 = 3.5 + 7.2
Side2 = 4.5
Hypotenuse = sqrt(side1side1) +(side2side2)
Print(“The hypotenuse is “, hypotenuse)
1) [#Wayne…] = Comment
2) [= 3.5 + 7.2] = Expression
3)[hypotenuse =] = variable
4)[sqrt] = function
5)[=4.5] = numeric literal
6)[”The hypotenuse is “] = string literal
7)[[ , hypotenuse] = Parameters