<jupyter_start><jupyter_text>Python Baby Steps - Krakens A primeira coisa que devemos fazer antes de começar a programar é...<jupyter_code>print('hello world!')<jupyter_output>hello world!<jupyter_text>Variables<jupyter_code>#string
first="Tom"
middle="Cruise"
last="Mapother"
print("Full Name:",first,middle,last)
print("Type:",type(first))


#numbers
base = 15
height = 22
area = 1/2*(base*height)
print("Area:", area)
print("Type:",type(area))


#boolean
learn_python=True
learn_fortran=False
print("Values:", learn_fortran, learn_python)
print("Type:",type(learn_python))<jupyter_output>Full Name: <NAME>
Type: <class 'str'>
Area: 165.0
Type: <class 'float'>
Values: False True
Type: <class 'bool'><jupyter_text>Input<jupyter_code>n1 = input("Enter first number: ")
n2 = input("Enter second number: ")
sum = float(n1)+float(n2)
# sum = n1 + n2
print("Sum is:",sum)<jupyter_output>Enter first number: 2
Enter second number: 3
Sum is: 5.0<jupyter_text>List<jupyter_code>colors = ['red','green','blue','yellow', 'black']
colors
type(colors)
colors[0]
colors[-1]
colors[1:3]
colors[:2]
colors[2:]
'red' in colors
'grey' in colors
colors.append('purple')
colors
colors.insert(2,'grey')
colors<jupyter_output><empty_output><jupyter_text>Dict<jupyter_code>members = {
    'board': 6,
    'hard': 8,
    'mark': 7,
    'mech': 9
}

def add():
    squad = input("Enter squad name to add: ")
    squad = squad.lower()
    if squad in members:
        print("Squad already exist in our dataset. Terminating")
        return
    p = input(f"Enter population for {squad}")
    p = int(p)
    members[squad]=p 
    print_all()

def remove():
    squad = input("Enter squad name to remove: ")
    squad = squad.lower()
    if squad not in members:
        print("Squad doesn't exist in our dataset. Terminating")
        return
    del members[squad]
    print_all()

def query():
    squad = input("Enter squad name to query: ")
    squad = squad.lower()
    if squad not in members:
        print("Squad doesn't exist in our dataset. Terminating")
        return
    print(f"Population of {squad} is: {members[squad]}")

def print_all():
    for squad, p in members.items():
        print(f"{squad}==>{p}")

def main():
    op = input("Enter operation (add, remove, query or print): ")
    if op.lower() == 'add':
        add()
    elif op.lower() == 'remove':
        remove()
    elif op.lower() == 'query':
        query()
    elif op.lower() == 'print':
        print_all()
 main()<jupyter_output>Enter operation (add, remove, query or print):add
Enter squad name to add:soft
Squad already exist in our dataset. Terminating<jupyter_text>Tuples (unchangeable)<jupyter_code>import math

def circle_calc(radius):
    area = math.pi*(radius**2)
    circumference = 2*math.pi*radius
    diameter = 2*radius
    return area, circumference,diameter

r = input("Enter a radius: ")
r = float(r)
area, c, d = circle_calc(r)
print(f"area {area}, circumference {c}, diameter {d}")<jupyter_output>Enter a radius:3.13
area 30.77786906795384, circumference 19.666370011472104, diameter 6.26<jupyter_text>Strings (and List idx operations)<jupyter_code>food='spam and eggs!'
food[0]
food[-1]
food[:4]
food[5:8]
food[9:]
len(food)
food.upper()<jupyter_output><empty_output><jupyter_text>If<jupyter_code>n = input("Enter a number: ")
n = int(n)
if n%2 == 0:
    print("Number is even")
else:
    print("Number is odd")
# Ternário
print("Ternary operator demo")
n = input("Enter a number:")
n = int(n)
message = "Number is even" if n%2==0 else "Number is odd"
print(message)	

brazil = ["sao paulo","rio de janeiro","itajuba","florianopolis"]
italy = ["roma","florenca","milao"]
eua = ["new york","los angeles","chicago"]

dish = input("Enter a dish city:")

if dish in brazil:
    print(f"{dish} is Brazil")
elif dish in italy:
    print(f"{dish} is Italy")
elif dish in eua:
    print(f"{dish} is USA")
else:
    print(f"Based on my limited knowledge, I don't know which cuisine is {dish}")<jupyter_output>Enter a dish city:itajuba
itajuba is Brazil<jupyter_text>Loop<jupyter_code>expenses = [1200,1500,1300,1700]

total = 0
for expense in expenses:
    total = total + expense
print(total)
total = 0 
for i in range(len(expenses)):
    print(f"Month {i+1}, expense: {expenses[i]}")
    total += expenses[i]
print(f"Total expenses is {total}")
num = 0
while num <= 10:
    print(num)
    num = num+1<jupyter_output>0
1
2
3
4
5
6
7
8
9
10<jupyter_text>Functions<jupyter_code>def print_pattern(n=5):
    for i in range(n):
        s = ''
        for j in range(i+1):
            s = f'{s}*' #using f-string
        print(s)

print("Print pattern with input=3")
print_pattern(3)

print("Print pattern with input=4")
print_pattern(4)

def calculate_area(dimension1,dimension2,shape="triangle"):
    if shape == "triangle":
        area = 1/2*(dimension1*dimension2) 
    elif shape == "rectangle":
        area = dimension1*dimension2 
    else:
        print("***Error: Input shape is neither triangle nor rectangle.")
        area = None 
    return area

base=10
height=5
triangle_area=calculate_area(base,height,"triangle")
print(f"Area of triangle is: {triangle_area}")

length=20
width=30
rectangle_area=calculate_area(length,width,"rectangle")
print(f"Area of rectangle is: {rectangle_area}")<jupyter_output>Area of triangle is: 25.0
Area of rectangle is: 600<jupyter_text>Read and Write<jupyter_code># read file
f=open("funny.txt","r")
for line in f:
    print(line)
f.close()

# write file
f=open("funny.txt","a")
f.write("\nI love python")
f.close()<jupyter_output><empty_output><jupyter_text>Have Fun<jupyter_code>import this
from __future__ import braces
import antigravity<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14732770745428972, 'fraction_numerical': 0.02549226441631505, 'mean_word_length': 4.599409448818897, 'pattern_counts': {'":': 2, '<': 46, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '459885', 'license': 'MIT', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2041, 'n_words': 534, 'path': 'Lectures/.ipynb_checkpoints/tutorial-checkpoint.ipynb', 'repo_name': 'luccasdt/KrakensGames', 'size': '5701'}