The BLOG OF CRAZY TIMES THAT ARE CRAZY (apcsp)






Welcome to the UNLAME CORNER! You want to learn how to CODE, so you're a cool guy (guy with sunglasses emoji).



PSEUDOCODE



Pseudocode is a way of how idiots (the ap people) make their code before they make their code (NOT COOL!)

Pseudocode is basically describing how a program will work, without using any specific coding language, so it is language-agnostic.



OUTPUT



Output is basically putting text into the Console.

To display something in AP Pseudocode, it's "DISPLAY ("Your Text")" (without the quotes)."

If pseudocode was real, then it would display "Your Text" (without quotes) into the console."

To display something in the console in Python, it's "print("Your Text")", again without the quotes."

This will print the same thing as the AP Pseudocode.



Data Types, String, Variables



The 4 primary types of data in Python are as follows:

Integer

Float

String

Boolean



An integer is any positive or negative whole number. A float is a number that contains a decimal.

A string is a series of characters surrounded by quotation marks. A boolean is true/false.



To declare a variable in AP Pseudocode, it's 'a ← "Your Variable"'

To declare a variable in Python, it's 'a = "Your Variable"'



To make a variable print to the console, declare your variable, and "DISPLAY (A)"

In python, it's "print(a)"

To print your variable with other text, you use a plus sign.

print("This is my variable: " + a



String Concatenation



To print your variable with other text (in python and pseudocode), you use a plus sign.


print("This is my variable: " + a) or in pseudocode DISPLAY (A + B)


If you want to concatenate strings and numbers, YOU CAN'T!

Well, you can. With a little CONCATENATION!


You have to change the number (integer or float) to a string

You may be asking, HOW DO I DO THIS?

Well, you just wrap your variable in str()


Like this: str(a)

Let's say A is 25. To print "I am 25 years old", you do


print("I am " + str(a) + " years old")


If you didn't concatenate, you would get an error.



Input



To get user input in pseudocode, it's "a ← INPUT ()"

To get user input in Python, it's "a = input()"

If for example you were making an addition calculator, and you got 57 instead of 13, your variables are strings.

To fix this, you need to make your variables from strings to integers.

Like this: a = int(input())

If your variables have decimals, they'll need to be floats.

Like this: a = float(input())

BUT! it needs to be a string to be concatenated with other text to be outputted!

So, if you wanted to make an addition calculator, your code would look something like this:



print("Enter a number:")
num1 = int(input())
print("Another number:")
num2 = int(input())
sum = num1 + num2
print("Your total is " + str(sum))


Comments


NO COMMENTS IN PSEUDOCODE!


That's cause pseudocode is the plan for your code, so no comments are needed, cause a computer couldn't run the pseudocode anyway.

Comments are for... making comments. They're to make the code easier and quicker to read.


They can be descriptions of the code, explanations, jokes, threats to overthrow the government of the Republic of the Congo, anything you want!

To comment in python, just use a hashtag, pound sign, number sign whatever you call it (this thing -> #) like this:


# This is a comment to comment the comment


You can also put them after code, like this:


print("Look at my awesome code!") # look at this dude's awesome code


That's about it for comments... cause they're well... just comments. NEXT SECTION!



Debugging Python



Errors in Python will happen a lot for you, because you suck! But! That's why you're here on this amazing website, to learn to code!

A syntax error is when the code is missing a symbol, letter, or other piece of information that stops the code from executing.

Most times your IDE can see syntax errors, and will underline them in red.


A logic error is when the programmer forgets to consider a scenario or uses incorrect ordering of code.


A runtime error is when you tell the computer to do something it cannot, like divide by zero.


An overflow error is when too much data is given to the program.

That's the end of Unit 1! I'd write more but it's 2:44 so HERE YA GO