"""This tutorial will show a lot of basic input/output functions and methods so that
you can start your python programming journey. It wil focus on efficiency and won't
be too complex, there will be more advanced tutorials on my channel in future, so be
sure to like and subscribe."""
#The first in-built function you need to know is print
print("Hello world")
"""This will allow you to display a piece of text of your choosing to the screen,
in this app it will display to the window on the right -->"""
#Now I will run the program
#So now let's do something a bit more advanced
#let's say we want to store something in memory then print it
#We use a variable, you can name it whatever you want, but it should be descriptive
name = "John"
"""That is one example of a variable, now we can use it to print the name of someone,
however, it doesn't need to be the only thing in the print statement, you can use a comma,
to seperate the name and any text you want to put in as well"""
print("My name is:",name)
...
#Welcome back to another python programming tutorial
"""Today we're gonna be building a program that lets
you print out a pattern using a for loop"""
#Start with some general numbers realted with the pattern
i = 5
j = 2
h = 3
#Now apply the for loop
for num in range(i):
#Now print an asterisk for each i
print("*"*i,end="")
...
"""Today we're going to show you guys how to build a
GUI calculator using tkinter and the math libraries"""
#First we need to import the libraries
import tkinter, math
#We then need to set up a global variable
expression = ""
#A main function needs to be created
def main():
#Some functions for the buttons are now needed
def press(num):
global expression
expression += str(num)
equation.set(expression)
...
#Numpy tips and tricks
import numpy as np
a = np.array([5,3,7])
b = 2
print(a+b)
"""Here this is called broadcasting, it allow the operator
addition to be applied between b and a element-wise, even
though b is just a numbver and a is an array it will add
b to each element of a"""
#Now let's run it
#We have to define data types for an array
dt = np.dtype([('name', np.str_, 16),
('age', np.int32),
('weight', np.float64)])
#Now we can create a structured array
data = np.array([('Jake', 19, 74.5),
('Sally', 23, 64.3),
('Jack', 16, 78.9)], dtype=dt)
#print(data)
...
#Today we will be looking at String methods and conditional statements
"""This program will closely examine some of the various string methods and also
will look at conditional statements (if, elif, else) and also the boolean operators"""
#below is an example of a string
myString = "Hello, This is a string!"
#First we'll start with string slicing
#print(myString[:5]) #This will print out the first 5 characters of 'myString'
#print(myString[10:]) #This will print from character 10 till the end
#print(myString[6:11]) #This will print from character 6 until character 10 (not including 11)
#You can also get a single character from a string, this time we'll ask the user
#character = int(input("Enter a character number (index) to retrieve from string: "))
#print("The character is:",myString[character])
...
Caesar Cipher Tutorial [Intermediate] (Short Tutorials)
Preview of code
#Caesar Cipher
#Now we have to define the function
def encrypt(text, key):
result = '' #setting up an empty variable first
#Now it's a for loop
for char in text:
if (char.isupper()):
result += chr((ord(char)+key-65)%26+65)
#Above, that is the formula for the encryption
else:
result += chr((ord(char)+key-97)%26+97)
#Now all we have to do is return the final result
return result
...
Find Max Num from File [Intermediate] (Short Tutorials)
Preview of code
#Max num from file, method 1
#First, let's open and read from the file
file = open("nums.txt")
fileContents = file.readlines()
#The first methiod is using a for loop
#Nearly forgot the variable
maxNum = 0
thisLine = 0
for count, line in enumerate(fileContents):
num = int(line.strip())
if num > maxNum:
maxNum = num
#using this method, we can aslo output the line num
thisLine = count
...
Loops [Iteration] and File Handling (Python Basics #3)
Preview of code
"""Ok so I've explained a bit about iteration loops and file handling, now we will
move on into the coding examples, be sure to follow along if you're watching
from home and want to learn python"""
"""#In a for loop, we don't need any pre-defined variables
for num in range(5):
print("The number is:",num)
#This will print out the numbers from 0 to 4 (not including 5)
#For loops are very useful, but only if we know the amount of times we're looping
for i in range(1,6):
#here we are looping from 1 to 5 (not including 6)
print("I have",i,"apples")
#Anyway now let's look at counting backwards
for count in range(5, 0, -1):
#-1 will allow us to go backwards by 1 each time
print("Numbers till countdown ends:",count)
#We can also loop in increments, for example every even number (up to a point)
for number in range(0, 22, 2):
#This will print out every even number from 0 to 20
print("The even number is:",number)
...