Skip to content

Instantly share code, notes, and snippets.

@Sanokei
Last active August 26, 2021 01:16
Show Gist options
  • Save Sanokei/a235aa3e43a9d79f622b6e3d8f112ab7 to your computer and use it in GitHub Desktop.
Save Sanokei/a235aa3e43a9d79f622b6e3d8f112ab7 to your computer and use it in GitHub Desktop.
Taught my friend basic python through discord

The basics are as follows

Comments:

# this is a comment, it wont do anything
# anything after a hashtag will not run for that line
'''if you have anything surrounding 3 single quote marks it will comment it out. so you dont have to comment every line'''

Variables and Types:

'''Variables let you store information in the program so you can use it later. You can change these, manipulate them however you like.'''

'''Basically you set the name of the variable you want then the equals sign to indicate that you want this to EQUAL something. Super easy to grasp. So when you see one equals sign. Think "setting variable". '''
This_is_a_variable = 0
# when you first create your variable, it is called initalization
'''You can choose what you name the variables however your name cannot have spaces or periods and cannot start with a number'''
#####----------------#####
Words = "Hello World" # use quotes for words

Many_Words = """Use 3 double quotes if you want to press enter and create a new line but want the string to continue"""
#####----------------#####
funny_number = 69
'''When you change funny_number, it cannot express decimals. For example saying "what is funny_number minus 1.5 ?" will give you the result 68, because its trying to display 68.5 but you set it as a type known as an integer. These can only express numbers without decimals'''

numberWithDecimalPlace = 4.20
'''now this can express decimals!'''

'''There is a thing called a list and it will be your best friend forever.'''
this_is_list_of_nums = [8,0,0,8,5]
hehe_your_mom = ["hehe","your","mom"] # you seperate the elements by commas
'''you initialize it the same as any other variable, but it can store a list of information. You can access the individual stuff in the elements by doing this_is_list_of_nums[0] The 0 in this case is the index you are trying to get and will be the first element in the list. You start by counting by 0 in any programming language. So to get the 5 in the list you could do this_is_list_of_nums[3] and now anytime you want to use the number 5 you can substitute it with this_is_list_of_nums[3].'''
#####----------------#####
'''You can use variables anywhere'''
my_words = "These are my words"
print(my_words) # This is called a print function, i will talk about it later

Operators:

- is minus
+ is plus
/ is divide
// is divide without considering the decimal place
* is multiply
** is to the power of 2**3 is saying 2 to the power of 3
< smaller than
> bigger than
<= smaller than or equal to !!!THIS WILL NOT MAKE YOUR VARIABLE EQUAL TO THE OTHER
>= bigger than or equal to 

-= subtract by element and make it equal to the new total !!!BUT THESE TWO WILL
+= do the same but add

In strings you can create tabs and new lines with
\t for tabs
\n for new line

Changing variables:

'''You can change varaibles at any time or create new ones'''
Player_Health = 20
Player_Defense = 5

# monster rawr xd
Monster_Damage = 3
Monster_Damage_Multiplier = 10

Player_Health = (Player_Health * Player_Defense) - (Monster_Damage * Monster_Damage_Multiplier)
'''Here we are rewritting the data for Player_Health to reflect the damage taken'''
#####----------------#####
Player_Health = 20
Player_Heal_Per_turn = 1

Monster_Damage = 3

Player_Health -= Monster_Damage
Player_Health += Player_Heal_Per_turn

Import:

'''So other smart people have made programs for us to use. You can import them before you write any code at the very top to start using the code they have written for us. You type import then the name of the package they have created'''
import random
Dice_6 = [1,2,3,4,5,6]
Rolling_The_Dice = random.choice(Dice_6)

Input and output:

'''You can output stuff to the player by using print'''
print("Your adventure starts here!")
'''You want the player to be able to input stuff into your program. You can put words in the parenteces to output to the player'''
Player_name = input("Enter your player name: ")
Player_social_security = input("Enter your social security number: ")

Conditionals:

Player_Health = 20
Enemy_Damage = 30

Player_Health -= Enemy_Damage

Dead = Player_Health <= 0

if(Dead): '''you can test IF something happens, and if its true'''
  print("You lost!")
'''to group parts of the program together you have to use indents.'''
if(Enemy_Damage >= 30): # this colon is important to indicate that you are starting a "group" of lines of code
  print("This enemy is Op it will be getting a nerf")
  Enemy_Damage -= 10
elif(Enemy_Damage <= 0): # elif means 'else if' if the first if is false then the elif will trigger
  print("This enemy is too nerfed it will be getting a nbuff")
else: # else just means if all the other if statements after the if > elif chain are all False
  print("This enemy is just right!")

Loops:

'''so lets say you want to repeat a process you would use a loop, there are two types of loops. While loops that repeat while the condition in it is true and For loops which repeat if one element is inside the range of the other.'''
while(True):
  print("this will loop forever")

attack_list = ["Fireball", "Ice Attack"]

print("I can use the attacks: ")
for attack_name in attack_list:
  print(attack_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment