PYTHON BASICS
Links
# INSTALLATION
# Download file from Python.org / IDE Pycharm (jetbrains)
# SETUP
# Create new proyect. Interpreter, choose the right version of Python regarding the version you have installed new python file
# FIRST PROGRAM : in ide click run button
print("Hello world")
print(" /|")
print(" / |")
print(" / |")
print("/___|")
print("|* *|")
print("| > |")
print(" \O/")
# coments
´´´
Multiple line comments
´´´
# DATA VARIABLES
character_name = "John"
character_age = 66
character_heigh = 1.85
is_Male = True
print("His name is "+ character_name +". He is " + character_age + "years old.")
# STRINGS
print("Giraffe\nAcademy")
print("Giraffe\"Academy") # prints ""
phrase = "Giraffe Academy"
print(phrase)
print(phrase +" is cool")
# FUNCTIONS
len(phrase) # giving the length of the string
phrase[0] # first character of the string
phrase.index("G") # Returns the index of the first character match
phrase.replace ("Giraffe", "Elephant") # Replaces certain strings
phrase.lower() # to lowercase
phrase.upper() # to uppercase
phrase.isupper() # checks, gives true or false
phrase.upper().isupper() # converts and then checks
# NUMBERS
print(3 + 4.5)
my_num = str(5) # converts number into string
print(my_num + "my favorite number") # to print with another string, the number must be parsed as string
# FUNCTIONS
abs(-6) # absolute number, transforms -5 into 5
pow(3,2) # 3 to 2
max(8, 6) # returns the higher number. opposite is: min
round(8.3)
# Other functions needs to import
from math import *
floor(8.8) # returns 8
ceil(8.3) # returns 9
sqrt(36) # square root
# INPUT FROM USERS
name = input("Enter your name: ")
# CALCULATOR
num1 = input("Enter a number: ")
num1 = input("Enter another number: ")
result = int(num1) + int(num2) # problem is that it won't allow to use decimals
# result = float(num1) + float(num2)
print(result)
# Mad Libs game
color = input("Enter a color: ")
plural_noun = input("Enter a plural_noun: ")
celebrity = input("Enter a celebrity: ")
print("Roses are "+ color)
print(plural_noun + " are blue")
print("I love " + celebrity)
# TRANSFORMATION
int(monthly_income)
float(monthly_income)
string(monthly_income)
city.lower()
city.upper()
city.title() - Add capital letter at the beginning of words