TEACH ME HOW TO BOT – Building a simple Twitter Bot

--Originally published at Coding The Future

Greetings everyone! I am back, and although this is long overdue, it's finally here!

Today I am releasing my tutorial on how to build a simple Twitter Bot. I have been working on a bot called Manny's Fortune Ball, a simple bot that replies with future predictions every time you ask it a question. You can go check it out by visiting its Twitter profile, and asking him a question. Its handle is @askemanuel.

Above I have attached a interactive slideshow. To move on to the next slide, just click on it, or tap the arrows.

Finally, this is the link to the GitHub repository so that you can check my source code: https://github.com/emamex98/TwitterFortuneBall

I hope you enjoy the tutorial! If you have any questions, do not hesitate to contact me:
Twitter: @emamex98
Email: em (at) nuel.xyz

comments powered by Disqus

Basic Types

--Originally published at Python

Basic types in Python 3 refers to most common variables that are used to program. These are known as numbers, string (words), List (group of variables), Tuple (similar), and Dictionary (again, very similar to the lists). Here’s a picture showing every basic type in use:

Code:

num = int(5)
print(“Number: “, num)

word = str(‘Hello’)
print(“String: “, word)

list1 = [‘Dog’, ‘Cat’, 9, 15]
print(“List: “, list1)

tuple1 = (‘Cat’, ‘Dog’, 15, 9)
print(“Tuple: “, tuple1)

dict = {‘Animal’ : ‘Dog’, ‘Age’ : 5, ‘Breed’ : ‘Pug’, ‘Name’ : ‘Bono’}
print(“dict[Animal]: ” , dict[‘Animal’])
print(“dic[Name]: ” , dict[‘Name’])

2basic

It may be hard to understand the difference between List, Tuple, and Dictionary by just looking at the program. List stores different types of variables that can be modified later on. Tuple does the same but can’t be changed. Finally, the variables in a Dictionary are accessed through keywords, not the position of the variable itself. Well that’s pretty much it for the basic types, hope you understood.


Python’s “Colors”

--Originally published at Just A Turtle Coding.

As everyone knows, life has its colors. Python does as well, everything you write is something, and those somethings have names. Owner taught me that while he gave me a “somethingberry”…

image

But he also tells me to bite small so I don’t choke myself… So lets bite small.

Variables

Variables are like the “berries” of Python. You can have STRAWberries, you can have RASPberries, you can have BLUEberries but they are all a part of the berries family.

Variables include numbers. Numbers are what the name says they are, numbers, but numbers have types also:

  • Int: a simple whole number. (Integer)
  • Long: a REAAAAAALLY long number.
  • Float: A number with decimal point.
  • Complex: A complex number. It’s usually written like: (9-4j) where 9 is the real part and the number followed by the letter “j” is the imaginary part.

You can also have another “berry”: Strings.

Strings are just characters (text or numbers) enclosed by a quotation marks. You can do all sorts of things with strings like write them lots of times by putting a * or add things to them. This image shows mostly everything <3

WHAT IF? Exploring If-statements

--Originally published at Coding The Future

Photo by Matthew Smiths

Many times in life we are faced with crossroads and have to make a decision. In coding, things work similarly. Sometimes, actions that the program triggers depend on what the user chooses or inputs. This is where if-statements come in handy.

An if-statement triggers different actions depending on a certain condition. By using if-statements, you can tell a computer to do this if a certain condition is met, and do something else if it isn't.

In Python 3, declaring an if-statement is quite simple. All you have to do is to type the keyword if followed by a condition, and close with a colon. Here's a quick example:

if logWeight > 23: print("Your suitcase exeeds the maximum weight allowed.")

As you can see, in the first line, I start by declaring an if, and then I state the condition, and close with a colon. The following indented lines specify the code that will be triggered if the condition is met. In natural language, it reads "if the suitcase's weight is greater than 23kg, print a warning message".

Let's say, however, you wanted to trigger a different action if the condition wasn't met. For example, if the suitcase's weight was less than 23kg. Then all you need to do is add an else to your statement. Take a look:

if logWeight > 23: print("Your suitcase exeeds the maximum weight allowed.")
else: print("Thank you for your business.")

As you can see, all I did was to add new line (non-indented though) with the keyword else, and told the program that if the weight was anything but greater than 23, then print a message thanking the the customer.

But let's say, you wanted to get really specific, and have different actions for different conditions. Instead

Continue reading "WHAT IF? Exploring If-statements"

LET’S MAKE COOKIES! An intro to Functions

--Originally published at Coding The Future

Photo by Jade Wulfraat

When I think of functions in any programming languages, I think of them as the reusable tools you use when baking cookies, for example. Here's why...

Every time you make cookies, you don't buy a new bowl, a new mixer, a new oven, and a new tray, or do you? If you do, you're just... something else. However, must of us reuse the same materials. There's obviously the ingredients that are single-use only, but most of the stuff can be reused and that is a good thing, because that way there's no need to buy a new tray every time we want to bake cookies.

Translating this into programming, if we are going to be using the same code several times, there's no point in writing it several times. It only makes sense to write it once, and use it (or call it as many times as we need to.

So basically, a function is "a block of organized, reusable code that is used to perform a single, related action" 1 that improves the efficiency and speed of your code. Remember that less lines of code means also better readability.

Defining a Function

When defining a function, start by typing the keyword def (I'm guessing it's short for define), followed by a unique name for the function, and then include brackets where any input parameters will also be declared (think of input parameters as the single-use ingredients that can change depending on what you want to achieve). Close the line with a colon.

In the following lines, which are always indented, is where the magic happens. You can include a explanation what the function does in the first line in quotation marks, although this is optional. This will not affect your function, and is often referred Continue reading "LET’S MAKE COOKIES! An intro to Functions"

I AIN’T GOT NO TYPE

--Originally published at Coding The Future

Image via GIPHY

Personally, I am not a rap fan, but again, I am making a reference to a song. This time, No Type by Rae Sremmurd came to mind when thinking about the different types of data you can work with on Python.

Even though we've already been working with them, let's discuss these data types in more detail...

  • Integers: They store a whole numeric value with no decimals, e.g.: 5.
  • Floats: They store a numeric value with decimals, e.g.: 23.43.
  • String: They store a string of characters of any type, e.g.: "Hello". Note that in Python there is no char (character) type. If you wanted to store only one character, use a string of length one. Also, just like it's name suggests, it is a string of characters tied together, so you can access each character using it's position. For example, in "Hello", string[1] is 'e'.
  • Booleans: They store a binary value of true or false. Basically, a variable of this type can only have a value of true or false. The false value can be expressed as 0, and true as any other number. E.g.: userIsMale = false.

Also, there are types in which several items can be stored within one variable. In other programming languages, they are usually called arrays, but in python they are somewhat different.

  • Lists: A list that stores several variables, and can be expansible. They are not limited to just storing one type of data; or in other words, you can store ints, strings, floats, in just one list. E.g.: list = [1, 2, hey, music, 12.34]
  • Tuples: Similar to a list, but static. Once it is declared, it remains fixed. E.g.: tuple = {1, 3, hello}

That's Continue reading "I AIN’T GOT NO TYPE"

I AIN’T GOT NO TYPE

--Originally published at Coding The Future

Image via GIPHY

Personally, I am not a rap fan, but again, I am making a reference to a song. This time, No Type by Rae Sremmurd came to mind when thinking about the different types of data you can work with on Python.

Even though we've already been working with them, let's discuss these data types in more detail...

  • Integers: They store a whole numeric value with no decimals, e.g.: 5.
  • Floats: They store a numeric value with decimals, e.g.: 23.43.
  • String: They store a string of characters of any type, e.g.: "Hello". Note that in Python there is no char (character) type. If you wanted to store only one character, use a string of length one. Also, just like it's name suggests, it is a string of characters tied together, so you can access each character using it's position. For example, in "Hello", string[1] is 'e'.
  • Booleans: They store a binary value of true or false. Basically, a variable of this type can only have a value of true or false. The false value can be expressed as 0, and true as any other number. E.g.: userIsMale = false.

Also, there are types in which several items can be stored within one variable. In other programming languages, they are usually called arrays, but in python they are somewhat different.

  • Lists: A list that stores several variables, and can be expansible. They are not limited to just storing one type of data; or in other words, you can store ints, strings, floats, in just one list. E.g.: list = [1, 2, hey, music, 12.34]
  • Tuples: Similar to a list, but static. Once it is declared, it remains fixed. E.g.: tuple = {1, 3, hello}

That's Continue reading "I AIN’T GOT NO TYPE"

ANSWER ME! Keeping the conversation alive…

--Originally published at Coding The Future

Image via GIPHY

I just realized I've been assuming in my previous articles that you readers know what output is... But I can't guarantee that.

To those of you who have been wondering what this print this, print that stuff is, here's a micro post on basic output for y'all.

Anytime you want text to be displayed when you run your program, for example, printing the value of a variable, or just a simple message, you can call the print class.

All you have to do after calling this built-in class is put text in parenthesis inside of the brackets or just the name of the variable.

Here's a quick example:

print("Hello World!")
print(userAge)

If we run this program, we will get the following (assuming userAge = 23):

Hello World
23

That's all for now. Stay tuned!
@emamex98

ANSWER ME! Keeping the conversation alive…

--Originally published at Coding The Future

Image via GIPHY

I just realized I've been assuming in my previous articles that you readers know what output is... But I can't guarantee that.

To those of you who have been wondering what this print this, print that stuff is, here's a micro post on basic output for y'all.

Anytime you want text to be displayed when you run your program, for example, printing the value of a variable, or just a simple message, you can call the print class.

All you have to do after calling this built-in class is put text in parenthesis inside of the brackets or just the name of the variable.

Here's a quick example:

print("Hello World!")
print(userAge)

If we run this program, we will get the following (assuming userAge = 23):

Hello World
23

That's all for now. Stay tuned!
@emamex98

SAY WHAT? Diving deeper into Input

--Originally published at Coding The Future

Image via GIPHY

Sometimes people say things I don't understand. However, when programming, understanding what a user is telling you is vital in order for a program to work.

In my last post, I talked briefly about the general syntax in Python 3, but this time I wanted to focus especially on user input, because I left this information incomplete last time. Let's get going!

Basic user input

Let's recall what we learned last time. When we ask a user for input, we can ask for several times of input. The most common ones are strings, which is just text; integers, which are numbers with no decimals, and floats, which are numbers with decimals.

Strings

When asking a user for input, the first thing that needs to be done is to declare a variable where the input will be stored. In the code below, a new variable called userName is declared, and then the input class is called. The text inside of the bracket is the prompt for the user to enter their name.

userName = input("What's your name? ")

Integers and Floats

Some times, input may include numbers, and even though they can be inputed as a string, they cannot be "treated" like numbers in that situation. In other words, let's say you are asking the user for their age and it will be stored in a variable called userAge, and then you want to add 10 to the value inputed. If the user input is stored in a string-type variable, you will not be able to add text to a number. For this reason, we have to specify that the input will be of type integer. To do this, you need call the int class and insert the input class within it.

userAge = int(input("How old are Continue reading "SAY WHAT? Diving deeper into Input"