Notizen
Fundamentals- Comp sci
Inhalt der Notizen (1)
Seite 1
Integers- positive and whole numbers
Floats- real numbers with decimal points
Strings- collection of characters
Lists- multiple pieces of data in one line, separated by commas
Type of errors:
Syntax- problem with spelling and grammar of the code
Runtime- problem with instructions of the code
Logic- problem with output, requires change to the code
Programming basics:
Print statements- whatever words or strings you want printed, use print (" ")
Escape codes-for coding in one line, you may need to indent (\t) or move to the next line (\n)
Math Operations:
Addition- number+number
Subtraction-number-number
Multiplication-number*number
Exponent-base**exponent
Division- number/number, results in float
Modulo- number%number, results in remainder after division
Integer division-number//number, outputs the integer of the answer
Variables:
Act as a container of information you need to store
Variables can be re-assigned
Variables can be inputted from the user and used as a string
Variable names must only be one word
For numbers- variableName=int(input())
For strings-variableName=input ()
Modules:
Modules can be imported into codes, for example to generate random numbers
Start off your code with import random
Next, whenever you want a random number generated, code variable=random.randint (number,number)
Boolean Values and Operators:
< less than, <= less than or equal to
== equality
>greater than, >=greater than or equal to
!= not equal
Codes can run under multiple conditions using certain statements.
And- can only be true when both conditions are true, false otherwise
Or- always true unless both are false
Not- flips true-> false and false-> true
Order Matters (Brackets, Not, And, Or)
If statements:
Used so programs can make decisions, only performs actions if true and skips otherwise.
if <Boolean condition>: only performs if statement is true
elif <Boolean condition>: only performs if first condition is false and second statement is true. (else if)
else: only performs if all previous statements are false
While loops:
Allows program to repeat until certain conditions are met.
while <Boolean condition>: only performs if statement is true, stops once condition is false
Defensive Coding: element of coding that won't let the program continue until the user enters valid input
For loops:
Used so program can repeat for a specific number of times.
for i in range (number1, number2)
Repeats number2-number1times
Always starts on number1
Can be used to repeat print statements or strings
i tracks where you are in the loop
Informationen
- Beschreibung
- Grade 11 Computer Science Notiz am Fundamentals- Comp sci, erstellt von L S am 15/02/2021.
- Erstellt von
- L S
- Aufrufe
- 0
- Tags
- Bewertung