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?"

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!

I WILL LOVE YOU WHILE [condition]:

--Originally published at Coding The Future

Image via GIPHY

I know. I've gotta stop with the song references. But today's topic reminds me of Whitney Houston's "Love You". That song is so beautiful, so inspiring, but it's all FALSE! Well, kind of... Why? Because nothing lasts forever. Well, maybe true love does. But in code, the chances you'll encounter a loop that never ends are super rare.

Today we'll be talking about while loops, which helps us run a piece of code while a certain condition is met.

For example, let's say we wanted to print a countdown. Instead of writing a single line for each number, we would just go to while loops!

While loops are super simple in Python. Begin with the keyword while and then write the condition –without brackets! The following lines, which are obviously indented, is where you put the code that'll loop. Take a look:

count = 0
while (count > 0): print ('The count is:' + count) count = count - 1

As you can see, the loop will run while count is grater than 0, and will stop running once count reaches 0. The count is decreased by 1

For your condition, you can use counters like the example above, or you could use a boolean value by nesting if-statements inside of your while loop. You've gotta be careful though, because as I said, you could get stuck into an infinite loop, which could break your program.

That's pretty much it for today. Until next time!
@emamex98

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"

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"

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"