The print-statment accepts any number arguments inside the parentheses seperated by
commas. The arguments get printed to the console
seperated by spaces and then at the end by default an line break is placed.
To change the default value at the end, you introduce one argument with end="".
The print-statment can print numbers and Strings(multiple characters inside quotationmarks).
Forgeting the quotationmarks in the print-statment often leds to errors, unless there is a
variable with that name, then the current value of the variable is printed.
Variables can be defined by writing the name you what to give them followed by an equal-sign
followed by their value.
Assining new values works exactly the same. When you want to add(+), subtract(-), multiply(*),
divide(/), whole-divide(//) or do modulo(%) on your variable, you can either write that your variable is equal
to an expression, which will be evaluated and then assigned to the variable or you can write
it shorter by writing the variable name followed by the operator followed by an expression.
The modulo-operator returns the remainder of an division.
The 'normal' divison results in an floating point value, whereas whole-division results in
integer values (if the numbers were integer).
Strings are a chain of characters(Symbols). A String can be created with single or
double quotes.
The mathmatical operators work diffrently on Strings. Adding Strings results in a longer
String. Multiplying a String by a number makes the String repeat that many times.
Adding a String with a number results in an error.
To change a number to a String you can use str(). To do the reverse you can use int().
Using comparison operators you can test for equality (==), inequality (!=) or greater (>) or smaller (<). The returned value is a boolean value and can be either True or False. The expressions on both sides of the comparison are evaluated first and then compared.
Using input() you can take an String as input. You can add an optional argument which will tell other users of your program, what to input. In the above code we take an input, then we convert it to an int value, so we can use mathmatical and comparison operators on the input, to test wheter the input is divisable by two or not.
An if-statment starts with the word 'if', followed by something which can be evaluated
to be True or False followed by a ':'. They are used to execute diffrent code when certain conditions
are True. The code which should be executed if the condition was True has to be
directly after the ':' in the next line. This code has to be indeted with whitespaces
or a tab. If needed you can add an 'else:' afterwards with another indented block of
code. This code will be executed when the condition is False.
In the code above it is used to make more understandable output.
An if-statment can be inside another if-statment. This can be nested as much as you need
In the code above it is used to determine in which categorie to put the coordinate.
Boolean values can be connected using logical operators.
"and" results in True if both values were True.
"or" results in True if either of the two values were True.
"not" inverts on value.
while-loops work exactly like if-statments, except instead of moving on to the code after it, the
condition is tested again and the code run again if it was True. This can be repeated as
many times as needed.
Be careful to not create infinite loops!
In the code above we use a variable to count up to the user input. Everytime we find a divisor,
we divide the input and print the factor. If there was no divisor we can move on counting up.
This way we get all primefactors and their occurance.
for-loops are similar to while-loops, but they are specialised in counting or going throw something.
A for-loop starts with the word for followed by a variable name followed by the word
in and then something which can be iterated.
Iteratable things include strings, like in this example or lists and many more.
Lists store multiples values and can be changed.
A list can be created using brackets. You can give some initial values, by writing them inside the brackets,
seperated by commas.
To add something to the end of the list you can write the variable name followed by a dot followed
by the function-name append(). Inside the parentheses you write what you want to add.