Connect SQL database in Python.

1. Open SQL Command Line Client or download from https://dev.mysql.com/doc/refman/5.6/en/mysql.html 2. Input your password 3. Now we have to create a database. 4. To avoid creating multiple databases, input: show DATABASES; # This will display already created database 5. Create a new database with this command: CREATE DATABASE pythonsql; # This will create the database …

More Loops

--[This is an example of a repeat...until loop--] --[[Local variable--]] a = 10 repeat print("Value of a: %s") %a a = a + 1 until(a > 15) --We're going to learn about nested loops. In nested loops, you can use another loop inside another. For instance all the loops. The while-loop, for-loop, repeat..until-loop among others. …

Decision making using If

--Decision Making --if statements: You can us if statements --if else: You can use if else statements --nested if statement: You can use one if statements inside another if statements or if else statements insid another if else --An if statement consists of a boolen expression and one or more statements --The syntax for if …

Identifiers

--[[In here, we discuss about identifiers in lua.--]] --[[Identifiers are words or letter that are used to name a variable, function,--]] --[[or maybe any user defined item. --]] --[[It could range from 'A-Z', 'a-z', underscore with letters or numbers--]] --[[Or well numbers ranging from '0-9'--]] --[[Lua does not accept punctuation characters such as @, $ …

Functions

--Functions --Functions are also known as method, sub-routine or procedure. They act as containers for other statements. --This is the syntax operational_function function function_name(arguments 1, arguments 2 ..argn) Example function max(num1, num2) if (num1 > num2) then result num1; else result num2; end return result; end --------------------------- function average(...) result = 0 local arg={...} for …

Design and Debugging

# Designing and Debugging # Hope you enjoyed the previous game. # You would realise that we used the for-loops and while-loops together. # You enjoyed youself right? I did too. # Can you in anyway get it expanded the more? # In here we discuss about designs and debugging. # Debugging is basically the …

Decision Making

# Making decisions. # This is very important in basic programming. # We are using knowledge gained from previous exercises. # Making decisions based on user inputs. # See if you can expand the game and have fun with it. def prompt print "> " end puts "You enter a dark room with doors. Do …

Functions and Files

# Functions and files # Game on # We add some new features or so here. # There is always something to learn I guess # We are using all that we previously learn't. input_file = ARGV[0] def print_all(f) # The print_all function is defined here puts f.read() end def rewind(f) # The rewind function …

Variables and Functions

# More practices I guess # We are doing more of variables and functions. include Ex26 def self.break_words(stuff) # This function will break up words for us. words = stuff.split(' ') words end def self.sort_words(words) # Sorts the words. words.sort() end def self.print_last_word(words) # Prints the last word after popping it off the end. word …

Object Class

# Let's briefly explain what a Class is and an Object. # A Class is more or less like the Reptile. # An Object is more or less like a Crocodile. # In programming terms, an object is an instance of a class. # Let's use the previous examples above here. Every Crocodile is part …

More Practice

# More practices in here. # puts "Let's practice everything." puts "You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs." poem = <<MULTI_LINE_STRING \tThe lovely world with logic so firmly planted cannot discern \n the needs of love nor comprehend passion from intuition and requires an explanation \n\t\twhere there …

Comments

# This is an extra credit of exercise 1 in Ruby Dawn # We should know what '#' does. It is called 'octothorpe' or can be called too as a 'hash', 'pound' or 'mesh'. puts "Dawn is a good Boss." puts "No doubt." # The statements after the pound character would not print. # It …

Else If

# We are building on the previous experience or exercise # Where we introduced the if-statement # We add another this time around again # Which is the else-if statement people = 30 cars = 40 buses = 15 if cars > people # If this statement is true, the expression below would print puts …

Libraries

# We are dealing with Libraries as a new topic in here. # More or less like 'files' we would need from ruby. # We call them Ruby Gems. They could be stuff you wrote yourself. # Or rather from Ruby require 'open-uri' open ("https://ruby-lang.org/en") do |f| f.each_line {|line| p line} puts f.base_uri # puts …

Ruby Game

# More exercises on Dictionary, Arrays and Functions # Lets try more of this in kind of a terminal game. # Remember the other we constructed? Lets build something new. # Similar formula though. Nothing to worry about. # Just keep in mind there are 3 ways of reading a code. # 1. Front to …

Elements and Arrays

# Accessing elements in an array. # Previously we learn't about the while-loops. # Then we played around the arrays too. # Now we need to learn how to access the elements in an array. animals = ['bear', 'python', 'peacock', 'kangaroo', 'whale', 'platypus'] # The elements in the arrays 'animals' arrays above would be use …

Data types

--Data types in Lua --The list of Data types for values are written below --nil, holds no values thus its nil --boolean, this is a variable type which can be eiher true or false --fucntion, this is a method of values written in either c or lua --string, this is an array of characters --userdata, …

Arithmetic

--Dealing with operators in Lua --An operator is a a symbol be it logical or mathematical that tells the innterprter what to do. --The types of Operators we got in lua is --Arithemetic Operators --Logical operators --Relational operators --Miscellanous Operators a = 21 b = 10 c = a + b print("Line 1 -Value of …

Strings Extra

# We continue what did previously. Thus, bringing sentences to the next line or multiple lines. # We have two ways to do this, using document syntax '<<' or back-slash with 'n'. # We are using escape sequences. Double and Single quotes inside a string "I am 6'2\" tall." # escape double-quote inside string 'I …

While-loops

# We're building from the previous lessons learn't on for-loops. # In here we learn about while-loops. # With while-loops, the expression would continue to print while the statement is true. # So obviously it could print for eternal. # So inorder for while-loops to stop, the statement muts become false at some point in …

Reading Arrays

# Reading Arrays # We are going to learn how to read arrays. # Remember we learnt how to read elements in an array? # We are going to build on it over here. # Obviously we add some new things to it too. ten_things = "Apples Oranges Crows Telephone Light Sugar" puts "Wait there's …

How to Read a Code

# Reading code # This is very important as you will get to know how other programmers go about coding in Ruby. # Do your best to find some Ruby scripts on the internet. # Read them, jot down some points or things new to you. # The idea is that by now you should …

Python Cheat game

Hello guys, I've created a terminal game in Python. Which is called the 'Cheat game'. With few questions could easily tell if you're a cheat or not. And well, there are even surprises too. Kindly visit https://github.com/lincollins/pygame download and try it out. Have you found any bugs or wants to improve it? Let's get interactive …

More on Variables

--[[Dealing with variables--]] --[[A variable is nothing but a name giving to a storage area that our program can manipulate from--]] --[[It can hold different types of from functions to tables--]] --[[There are 3 types of variables, Global, local and table--]] --[[When a variable is declared Global, it can be used anywhere in the program--]] …

Values

--Lvalues and Rvalues --Lvalue refers to an expression which implies the allocation of memory. Lvalue can be on the left-side as well as the right-side. --Rvalue refers to a data value that has an address location in the memory. It has no value and thus can only be on the right and never on the …