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

YOUR ARGUMENT IS INVALID, isn’t it?

--Originally published at Coding The Future

via GIPHY

If you had been in my house while I was watching the US Presidential Debates you would probably had heard me scream to my computer "YOUR ARGUMENT IS INVALID DONALD!". Not only do I hate that guy for being so racist, but also because everything he says is just so dumb. And then my girl Hillary comes in saying that you can fact-check Donald from her website in real time. Gotta love that QUEEN!

But aside from US politics, let's move on to today's topic: validating user input. This will not exactly help us to fact-check Donald, but to make sure that the user is entering the right kind of information.

Let's take a registration form for example. We want to collect the user's name, email, and phone number. Therefore, we must make sure that the user includes an @ and a .something and that only numbers are inputted in the phone number field. Here's how it works...

Using the "Try" Approach

To validate input, we could use if-statements, but there's a more effective approach commonly known as Try-catch. This method tries to do something, and if it can't, instead of crashing the program, makes it do something else.

Take a look at the following sample code:

try: phoneNum = int(input("Please enter your phone #: ")) except ValueError: print("Sorry, that phone number is not valid.")

As you can see, the first step was to type try followed by the code you need to validate, which in this case is making sure the input only whole numbers, and then using an except statement to break out of if an error was returned. This prevents the program from crashing, and if combined with a while loop, can prompt the user to enter their number again until they get Continue reading "YOUR ARGUMENT IS INVALID, isn’t it?"

DO NOT READ THIS!!

--Originally published at Coding The Future

Original image by Romain Vignes.

Hello! Ok, I must begging by saying that reading this article will not kill you nor hurt you in any way. In fact, it will be beneficial! So why the title, you may ask? Just to catch your attention! ?

Today's topic is reading and writing text files. This is one of the most important aspects in programming, because if you think about it, 99% of things online are text-based. Think about it... although Google has the option to search through voice and image, 99.9% of the times you probably just type what you need to find and hit enter. See? This is why programs must be able to interpret text because we live in a text-based world.

I want to get things clear though... When I say text files, I am not referring to MS Word documents –those are processed word docs– instead of plain .txt files. Let's get going.

Opening text files

Let's begging by looking at how to open a text file, which is the first step to reading or writing on the file.

In order to do this, we will need to declare a variable where a text file object will be stored. To do so, use the open( ) method and pass the filename as a parameter.

textFile = open(loremIpsum.txt)

Reading text files

Once we have the text stored in textFile, our sample variable, we can read it to process its contents. To do so, we need to use the .read() function.

In the following sample code, I read the text file I previously imported and print it:

print(textFile.read())

As you can see, since the text file is already stored in the textFile variable, I use the function within the file object.

Processing files

By processing, Continue reading "DO NOT READ THIS!!"

FORever ALONE

--Originally published at Coding The Future

Image via GIPHY

Today, I will share the very sad story of my relationship life: I am, and forever will be a forever alone. But that's ok. To be honest, I don't mind the single life. Love's just complicated for me.

But anyways, you are probably wondering why am I telling you this, which is probably useless. Well it kind of is useless, but today's topic, For Loops, got me thinking.

So, let's dive into today's topic: For Loops. Remember while loops? Well for loops are not so difference. Only difference is that this time, we know exactly how many times the loop needs to run.

Here's an example: Let's say we wanted to ask a user to enter their password, and we need the user to enter it twice. Since we know that the loop will run exactly twice, the most appropriate way to accomplish this is a for loop. Let's take a look at the following program:

password = ["pass1","pass2"]
i=0;

for counter in range(0,2):
⠀⠀password[counter] = input("Please enter your password: ")
⠀⠀i= i+1

if (password[0] == password[1]):
⠀⠀print("Both passwords match")
else:
⠀⠀print("Passwords do not match")

As you can see, the first two lines simply declare a list and an integer. The following lines is where the magic happens. As you can see, I started with the keyword for, and declared a counter variable called counter, followed by the key words in range and the range from which the loop will run. As you can see, this range is in brackets, and it says (0,2). Check the footnote to know why this means it will run twice.1 I end off with a colon.

The code bellow just asks the user for input, stores it in a list, and at the end of the loop Continue reading "FORever ALONE"

FOR ALL THOSE PROCRASTINATORS

--Originally published at Coding The Future

If you are reading this right now, you were probably procrastinating, and just started studying for tomorrow's test, right?

Well, as always, I've got you covered. Here's a quick video summary of what you need to know for the first partial. I hope things are not too strange.

Good luck!

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

I DON’T SPEAK GERMAN (BUT I CAN IF YOU LIKE)

--Originally published at Coding The Future

If you are a Lady Gaga fan, you are probably familiar with her famous line "I don't speak German, but I can if you like" from her song SchieBe. This lyric line has always intrigued me, but it has acquired a new meaning since I started programming. Why? Because once you learn an object-oriented language, all others come naturally in a matter of days.

I started coding on Python 3 for the first time last week, and coming from C# on Visual Studio 2008 felt like a natural transition. All the syntax is pretty much the same, and some is even simpler, which is an amazing thing!

I have taken the time to compile the most basic syntax that I've learned on Python so far. Enjoy!

1. Comments

When we think about coding, commenting often goes as an underestimated feature. Consequently, I decided to start my post with comments.

#COMMENTS: To comment, use a number sign and then write your comment.

2. Declaring variables (and arrays)

Unlike other programming languages, I've realized that on Python, you don't have to declare the variable type when declaring a variable. To declare a variable, just type the name, and if you want to, give it a value. Even though you don't need to, I usually give integer-type variables a default value of zero. You can also declare strings and arrays using the appropriate brackets.

i = 5 j = 6
k = i + j
y = [1,3,5,8]
x = ('Emanuel')

3. Output

To output a variable or just some text, you can use the print class. Remember you can always combine several variables or variables with text by concatenating using the plus sign.

print ('Hello World!') print ('Hello, ' + x)
print (k)
print (y)
print (y[2])

4. Input

I'll be Continue reading "I DON’T SPEAK GERMAN (BUT I CAN IF YOU LIKE)"

I DON’T SPEAK GERMAN… But I can if you like

--Originally published at Coding The Future

If you are a Lady Gaga fan, you are probably familiar with her famous line "I don't speak German, but I can if you like" from her song SchieBe. This lyric line has always intrigued me, but it has acquired a new meaning since I started programming. Why? Because once you learn an object-oriented language, all others come naturally in a matter of days.

I started coding on Python 3 for the first time last week, and coming from C# on Visual Studio 2008 felt like a natural transition. All the syntax is pretty much the same, and some is even simpler, which is an amazing thing!

I have taken the time to compile the most basic syntax that I've learned on Python so far. Enjoy!

1. Comments

When we think about coding, commenting often goes as an underestimated feature. Consequently, I decided to start my post with comments.

#COMMENTS: To comment, use a number sign and then write your comment.

2. Declaring variables (and arrays)

Unlike other programming languages, I've realized that on Python, you don't have to declare the variable type when declaring a variable. To declare a variable, just type the name, and if you want to, give it a value. Even though you don't need to, I usually give integer-type variables a default value of zero. You can also declare strings and arrays using the appropriate brackets.

i = 5
j = 6
k = i + j
y = [1,3,5,8]
x = ('Emanuel')

3. Output

To output a variable or just some text, you can use the print class. Remember you can always combine several variables or variables with text by concatenating using the plus sign.

print ('Hello World!')
print ('Hello, ' + x)
print (k)
print (y)
print (y[2])

4. Input

I'll be Continue reading "I DON’T SPEAK GERMAN… But I can if you like"

I DON’T SPEAK GERMAN… But I can if you like

--Originally published at Coding The Future

If you are a Lady Gaga fan, you are probably familiar with her famous line "I don't speak German, but I can if you like" from her song SchieBe. This lyric line has always intrigued me, but it has acquired a new meaning since I started programming. Why? Because once you learn an object-oriented language, all others come naturally in a matter of days.

I started coding on Python 3 for the first time last week, and coming from C# on Visual Studio 2008 felt like a natural transition. All the syntax is pretty much the same, and some is even simpler, which is an amazing thing!

I have taken the time to compile the most basic syntax that I've learned on Python so far. Enjoy!

1. Comments

When we think about coding, commenting often goes as an underestimated feature. Consequently, I decided to start my post with comments.

#COMMENTS: To comment, use a number sign and then write your comment.

2. Declaring variables (and arrays)

Unlike other programming languages, I've realized that on Python, you don't have to declare the variable type when declaring a variable. To declare a variable, just type the name, and if you want to, give it a value. Even though you don't need to, I usually give integer-type variables a default value of zero. You can also declare strings and arrays using the appropriate brackets.

i = 5
j = 6
k = i + j
y = [1,3,5,8]
x = ('Emanuel')

3. Output

To output a variable or just some text, you can use the print class. Remember you can always combine several variables or variables with text by concatenating using the plus sign.

print ('Hello World!')
print ('Hello, ' + x)
print (k)
print (y)
print (y[2])

4. Input

I'll be Continue reading "I DON’T SPEAK GERMAN… But I can if you like"