Now that we’ve created our project called Note Taker, you’ll notice there are 4 folders. The first one just called NoteTaker is our shared project. Now this folder is where we’re going to store all of our shared code. So, all of the code for example, in this file if I double click it, it will open it is accessible using both NoteTaker.droid for Android and NoteTaker.iOS for iPhone and iPad. If you put code for example in NoteTaker.droid NoteTaker.iOS won’t be able to access it, and there’s a very good reason for that it’s because iOS and Android are very different code-wise. So, you never want to share your iOS with your Droid code, ever, ever, ever! Sometimes within the shared project we can have what they called a conditional compiler, which looks something like this. If, Android and we can write endif and #endif, and this basically says, anything I write here will be applied to anything I want to build for iOS, and anything I write here will be applied to anything I want to write for Android. If I want to write for Android, it will of course ignore everything in the iOS section, but we will come to that much later on. That’s just a quick note. Ok, going to close that. So, if we come down on our folders here, we have NoteTaker.droid and NoteTaker.iOS. Now, the iOS one is in bold. That means it’s the currently active one. So when we click play up here it’s going to send it to our iPhone, or to our simulator, or our iOS device, to whatever we’ve chosen. If we want to change which project we have active, you go to droid, you right+click, and you go to set as start up project. So if I click that now, it now comes up at the top with the bunch of Android devices. Now, sometimes you would be in let’s say release and then you right+click a project, and you won’t have set a start up project. It’s a common error that happens and I don’t know why Xamarin does it, but just know it’s best to click debug iPhone simulator, right click and then it appears again. Ok, so make sure that you’ve selected iOS as your start up project. Close your Droid one, because we don’t want to look at that in the moment. So, in your iOS project we have a bunch of folders once again, and these base folders that your project starts with you should never ever move or change the name of. You can add folders to here if you right click it and you click add new folder, that’s absolutely fine. However, these four here you should never delete. Otherwise, your app will not build and you’ll have lots of errors. So, I mentioned it earlier but it should go without saying, any code we write for Apple goes into here: NoteTaker.iOS. Any code you write for Android goes in here: NoteTaker.Droid, and we never want to mix the code between the two. Shared code goes into just NoteTaker and that code in NoteTaker will be accessible by both Android and iOS. Now that we’ve covered where we put our code, and the whole project structure, join me in the next lesson when we walk through the Xamarin Studio graphical user interface.
Tag: development
Creating a Xamarin Project
Now that you’ve got Xamarin installed, I want you to go ahead and open up Xamarin Studio. Note that you can follow this tutorial using Visual Studio using the Xamarin Plug-ins for that, and the workflow is pretty much the same. So, if you want to go that way that’s absolutely fine, but we’re gonna use Xamarin Studio. Once you’ve opened it, you are effectively in a lite version of Xamarin Studio, and what we need to do for this course to is to create ourselves a Xamarin account. So, if you click this log in button in the top corner it will ask you for your account details. We don’t have those at the moment. So come down here and click create account, and once you do that it will take you to this page on Xamarin’s website. You just put in your name, email, password, and you have the option here, to start a 30-day Xamarin trial. Now, this gives you access to the business version of Xamarin, which is what we want. Once you have finished this course the business version is the one that you should have if you want to use Visual Studio. You can get by on the Xamarin Indie Edition, which is much much cheaper, I think it’s a quarter of the price of the business version per year. This indie edition is perfectly fine for personal projects. So, once you’ve done all that click accept, and then come back here and enter your details. Once you’ve done that and you’ve clicked logged in, it will tell you: “You are now subscribed to Xamarin business.” I can subscribe on four computers, but on a trial I think you can only subscribe on two computers. So go ahead and close that. Let’s get started with creating our very first solution. So, come over here and click new solution. Now, if we look through the various options we have here, we have cross platform iOS, Android, Mac and other. If you’re only going to create an app for a single platform i.e., iOS or Android that’s fine, you can choose one of these options. I would advise to always choose cross platform because if you so decide you can add another platform later, and it’s going to be a lot easier than trying get all of your files together. So, we will click app and now you have a choice on cross platform, we can either do forms or native. Personally, I’ve used Xamarin forms and if you look over here in descriptions, it doesn’t actually say anymore, but it used to. Xamarin forms lets you write ones and run everywhere even on the graphical user interface which can be a good thing, but it can also be a bad thing because you can’t use the full system resources and various user-designed processes on Android or iOS if you use a generic version. But, if you choose a single view app, it allows you to use the entire Graphical User Interface native to each platform. So you can use everything that iOS can do and you can use everything that Android can do, and forms doesn’t let you do that. So, I would always choose single view app. Click next. It’s going to ask you for an app name and this could be anything you like. So, we’re just gonna call this note taker, and you’ll notice down here it doesn’t identify it for you. Now, this indentifier is going to be used to identify your app within the phone ecosystem on both Apple and Android. It’s typically formed of three words each separated by a period, and the first one is always com, the next one is your company name, but in this case I just put my name .grant.note_taker, and this is a unique identifier for your app. Right, so if you go to your Android developer account or your Apple developer account this identifier must be free. You’ve got to make sure that it’s free. Then we come down to shared code. We can either use what’s called a portable class library or a shared library, and the only difference between these two is how easy it is to share your code with other developers. If you want to share your code, and package it in one file, and to send it to loads of people you use a portable class library. If you want your code to allow you to do a lot more things then we use a shared library, and generally, I would say, let’s use a shared library and you can’t share your code as easily with people, but it allows you to do a lot more. We’re gonna take advantage of that so we can write a shared database later for both of our apps. So, go ahead and click next. It will ask you for a project name and a solution name. I would ignore this for now, just leave it as the default and I will explain what that means a bit later on. Lastly, you want to save it. So, wherever you want to save it it’s fine. You can save your projects in Dropbox. It syncs absolutely fine, no problems. So we’re gonna hit create and once it has worked through what it needs to do you come over here, and you’ll notice you have a bunch of essential folders, a tree structure. So, we’re going along like this. In the next lecture I’m going to explain exactly what each level of that tree structure is and how we’re going to structure all of our apps relative to these trees that you see here. So, join me for the next lecture.
How much money can you make as an app developer?
I’ll just go through a couple of the numbers that I have when I first started out making apps. I started out making apps just for myself because I needed various things other apps couldn’t do. It was more a curiousity, if thing. Curiousity will take you very far in development as well. I found my very first client on a freelance website, and he wanted an android app to record a voiceover track. For that I charged him 200 pounds, which was for the first version. Following that, he said he would like to have this on Apple, and he would like to publish it on the app store with various enhancements and Facebook sharing. To do that he paid me 2,700 pounds. Later on he asked for a few more customizations, and so that added up to another 1,800 pounds, and in total it was about 4,500 pounds for that app. Now, that first app took me a month to make, and that was with me as a relatively new beginner to the app development world. Following that, he requested the app on Android and I charged him again 4,500 pounds to put it on Android, and that took me 2 weeks. So, you can see the potential really to make money is there. You can make a lot of money developing apps. I will tell you don’t keep your eye on the money at first, keep an eye on becoming a good programmer. I put LEARN in capitals because that’s what you need to do for the first 6 months. So, you need to be in this for the long haul, and once you’ve been through the long haul, money like this will be absolutely nothing because once you know how everything works, business can come to you. You want business customers because they will request a demonstration app which you can charge and average of 10-20 thousand pounds, and that will take you a month at most. Once they have that they’ll then be confident to invest in you. Depending on the app, I mean the sky is the limit, and we will be looking at 100k to 500k. So, throughout this course. I want you to follow it carefully. If you don’t understand something, ask. Also, I want you to go on YouTube, and on Google, and search for various things that you see popping up. So, with that said, I look forward to seeing you in the next section and we will get on with setting up our brand new project in Xamarin Studio.
Xamarin Setup
The very very first thing we need to do is install Xcode, by Apple. Xcode is the traditional way of creating Apple apps. To use Xcode, you have to learn a language called Swift, but we’re using C# and what Xamarin does is it goes to Xcode with its C# code and says could you translate this for me? It’s not the completely correct way of describing it, but it will do for now. So go ahead and download Xcode and install it, and install all of the things it asks you to install. I’ll just point out one thing down here if you are a novice programmer. If we look at this customer review, he goes: “I mean seriously, why would you cast a swift array to an NS array?” If you are new to programming, you’ll come across this a lot. The correct way to do things, the opinionated way to do things, and I will tell you right now, there is no right way, there is no wrong way. Well, ocassionally there is a wrong way. But there’s no right way there are many ways to do things in programming, and that way, it’s more of an art form. So, once you have learned the basics then you can really do it the way your brain works. Okay, so if you come across someone else’s opinion, they say you should do it like this, or like that, don’t be afraid to fight back with what you think. Once you’ve installed Xcode your next step is to go and get Xamarin, and to do that you simply go to Xamarin.com, you click download, you fill out the form, and you download for OSX, and of course you could also get it for Windows. But, if you want to build your app for iOS, you need to be connected to another Mac. This is why I’m doing the whole course on OSX. So, we don’t have to worry about that, but just know you can do that. So, once you’ve downloaded Xamarin open up your installer, and it’s going to present you with a whole bunch of options to install Xamarin. Now, there are very a few sections of Xamarin that we need to consider installing, and it’s about to tell us what we need. You can have Xamarin.Android, Xamarin.iOS and Xamarin.Mac So, I have all of these installed, even .Android, I don’t know why it’s telling me I need a new one. Perhaps it’s an update. Once you’ve gone through and installed that, and you’ve continued, it will give you a screen that asks for prerequisites, like the Java development kit, the Google SDK, and various other bits and pieces. So, go ahead and install all of those, and once you’re done, please join me for the next lesson. I’m going to give you a quick overview of my personal experience with charging for apps, and that will be my experience where I have gone out and contracted with clients to make apps for. I’m sure that’s information that a lot of people would actually like to know.
Xamarin Hardware Requirements
So now we have to setup our hardware, which for this series of tutorials is ideally going to be a Mac. This can be any kind of Mac. A MacPro, a MacBook any of the older Macs as long as they run at least Yosemite, which is most of them at this point. I am currently using MacBook Pro, but as you can see they are pretty expensive. I couldn’t afford a MacBookPro until I got my first paycheck for one of my first apps, which was about 1,5000 pounds, and I bought a 13-inch MacBookPro with that. I can understand that perhaps you don’t want to make that investment right now, so an alternative is to buy a used MacBook, one of the older ones will be fine for what we are doing. Alternatively, you can go to websites like tonymacx86.com and these websites tell you how to put together New Entry 32 hardware so you can run OSX on a custom built PC. On tonymacx86 there are several articles that will assist you with building a custom Mac, and it gives you a list of ingredients, a recipe if you will, of all the necessary hardware components. Now, if you’re not comfortable with that, that’s fine. You can go to their laptop guides, and you can buy an off-the-shelf laptop and there are lots of helpful people on these forums that will tell you how to install OSX. So we can use ASUS, Lenovo, there’s all different kinds. Personally, I started with an HP EliteBook. I would recommend, if you’re going to configure what is called a Hackintosh, this is definitely where you should start. I’d recommend the model 8470p or something along the 8400 line. You can also have an 8440p. If you go back to the tonymac website and you look in the forum, there are a lot of recommendations. These EliteBooks have had an installer made by tonymac that lets you install OSX without too much fuss. So, I’d recommend that. The reason we need to run everything on a Mac is because iOS apps for iPhones and iPads will only be compiled on a Mac, and we need to use specific Mac software. Okay, with that said, once you’ve got your hardware setup, please go on to the next lesson where we will setup Xamarin, and all of the required software.
Xamarin Course Overview
Let’s cover the things that you are actually going to learn in this course. It’s going to be very hands-on. So, I will not provide finalized files as much as possible because I need
you to write the code yourself, and that is the best way to learn. Simply copying will not produce good code. Now, the first thing we’re going to learn about is basic C# code, and this is the language used in Xamarin. C# is a language invented by Microsoft to go along with the .NET framework, and it’s a very elegant language, and in my opinion it is one of the better languages you can start by learning. It’s very modern and it takes all of the best parts of the other languages and puts them together in one place. In Xamarin, you can use another
language called F# and I believe you can use Visual Basic, but don’t quote me on that. I wouldn’t go down that route if I were you, I would stick with C# because most of the examples on the internet are in that language. Secondly, I assume, you know absolutely nothing about programming. So, I will leave nothing out. At times, this may seem laborious, and if you already know about programming you might roll your eyes and think, “Dude, I already know that.” But, it is more important to include everything at the risk of boredom rather than not include it, because at the end of this course I don’t want to leave you with lingering questions about why things are and how they work. Then we’re going to learn the basic structure of an iOS App. Since all Apple apps tend to follow a specific design pattern, and it’s very much the same with android apps, they follow a specific pattern. So if you think about both platforms, if you have ever scrolled through a list of things, both of the platforms implement a list. In iOS it is called a Table View and in Android it’s called a List View, and these are just a list of things and you can define whatever that thing is, but each operating system in both Apple and Android take care of all the heavy lifting for you in the background. Next, we’re gonna look at how to write as much shared code as possible for our apps. So, if we come back up here, I should put in one more thing, and this is going to be a database layer and then a data access layer. And then, we go down to the basic structure of iOS and Android apps. And now, these two sections are shared code and these two sections can be used by both iOS and android without modifying them at all, and that is fantastic because you will save about a third of your time because you’ve already written the base logic code for each app. And it doesn’t end there, because Xamarin will allow you to write Windows phone apps, and it will allow you to write Windows Desktop applications, as well as Mac applications. So, it’s absolutely great for that. Right, second to last, I’m going to show you how to use SQlite databases on your devices. Now, most mobile devices come with this as a standard. To access SQlite databases, if you know about anything about databases, you’ll know we need to know a database query language. But, for this course we don’t need to go into that because we’re going to use a very popular library called SQlite.net which is free on most platforms, in fact all platforms, I think. This concept of a database you’re going to use time and time again with any apps you create. Absolutely any app you create! If you want to save data, this is how you’ll do it. Finally, we’re going to look at some of the common pitfalls in mobile app development. The primary of which, will be things like memory leaks. So, if I have say an image, this image requires memory. If I load another image, then that’s going to add some more memory in use. As you know, mobile devices don’t have a lot of memory, so you can reach a point where memory will be full. At those points your app will usually crash, and the app doesn’t work anymore. So, I’m going to give you a few pointers in both platforms on how to avoid this common pitfall. So, join me in lecture 3 when we’ll begin setting up our Mac or PC.
FREE Python Programming Course on Teachable
If you want to learn how to program, you will LOVE this course! This course was designed for complete beginners with little to no understanding of programming, and will give you the knowledge to get started coding using Python 3.
Enroll now for FREE on Teachable!
We will cover the following topics in this course:
- Python installation
- Running Python scripts in terminal
- PyCharm IDE setup
- Numbers, strings, Boolean operators, lists, dictionaries, and variables
- Functions, arguments, return values, loops, and modules
- Final project using the information covered in the course
We hope you enjoy the course and it our goal to give you the knowledge to begin writing your own programs in Python!
(FREE) Python Programming Course on Udemy!
If you want to learn how to program, you will LOVE this Udemy course! This course was designed for complete beginners with little to no understanding of programming, and will give you the knowledge to get started coding using Python 3.
Enroll for FREE on Udemy
We will cover the following topics in this course:
- Python installation
- Running Python scripts in terminal
- PyCharm IDE setup
- Numbers, strings, Boolean operators, lists, dictionaries, and variables
- Functions, arguments, return values, loops, and modules
- Final project using the information covered in the course
We hope you enjoy the course and it our goal to give you the knowledge to begin writing your own programs in Python!
The Complete Linux Course: Beginner to Power User!
Get The Complete Linux Administration Course Bundle!
https://josephdelgadillo.com/product/linux-course-bundle/
Enroll in the courses directly on Udemy!
A Beginner’s Guide to Linux System Administration!
http://bit.ly/2gHV6dD
CentOS and Red Hat Linux to Certified System Administrator!
http://bit.ly/2h7ONwE
BASH Programming Course: Master the Linux Command Line!
http://bit.ly/2y4GyY8
The Complete Wireshark Course: Go From Beginner to Advanced!
http://bit.ly/2yLpqIy
Together we’re going to take a journey through Linux and give you the knowledge you need to be a power user, but first we must ask the question, what is Linux? Well, confusingly it depends on who you ask. In order to get an idea of what Linux is we’ve gotta go back in time. In the early 1980’s Richard Stallman, then working in the AI lab at MIT, started the GNU project with the goal of creating an entirely free and open Unix-like operating system. This all started when the lab got a new printer, but the license restricted his ability to modify the code. He had hacked earlier printers to electronically send messages to users who printed items when the printing was complete, as well as notifying other users when the printer was free to use. By the early 1990’s there was almost enough GNU software to create an entire operating system, however their kernel, the GNU Hurd, was not yet complete. Meanwhile, in the early 1990’s Linus Torvalds set out on a hobby project to develop Unix-like colonel known as Linux, and used GNU software such as GNU’s “C” compiler to do it. While a kernel on its own was useless, he ended up including GNU software with the kernel tree to release an operating system. Later, Richard Stallman’s free software foundation sponsored the group Debian to release a GNU/Linux distribution that was completely open for people to use and contribute to. Debian over the years grew from a small group of Free Software Foundation hackers, to the enormous community that is today. Due to its popularity, Debian has become the base of countless Linux distributions. Because of how open the software is, anybody to read the source code, modify it, and then redistribute it. Because of this, this is what we have now, it’s kind of a mess. There are so many Linux distributions that a common problem for beginners is what Linux distribution should I use. While there are a few distros out there that actually include its own software, one of the biggest problems in Linux is how many distros there are and the fact that a lot of them are the same distribution with new wallpapers, and icons, and everything else is the same. Ubuntu was started in the early 2000’s and is owned and distributed by Canonical. The base of Ubuntu is Debian, and Ubuntu has become so popular that it has in turn been forked countless times. Forking is a process which the operating system is used as the base of a new distribution. Ubuntu includes it’s own desktop environment called Unity, and has recently started distributing phones running a version of Ubuntu. Canonical also contributes bug fixes and other contributions upstream, meaning that they send these changes back to Debian to include in future releases. While Debian releases new versions sporadically, Ubuntu’s aim was to capture the stability of Debian, but released new versions more frequently. As such, Canonical releases two distributions a year, one in April and one in October. The naming convention of Ubuntu is year & month. So, the version we’ll be working with was released in October of 2015 and it’s called Ubuntu 15.10. Every two years in April, a long-term support version is released called LTS, which is officially supported for five years. While releases in between LTS versions are supported for only 9 months, the next LTS release will be in April of 2016. So, to download Ubuntu we’re going to go to Ubuntu.com, and when the page loads we’re going to see in the top navigation that there’s an option that says desktop. Just click on that, this is the version of Ubuntu we’re gonna be working with, and then when you get on the overview page, just click download Ubuntu, the big orange button in the main area. And on this page it’s gonna give us a few versions, so it’s gonna prompt us to download the last LTS release which was released 2014, in April. If you’re gonna be running Ubuntu on a server it makes sense to you long-term support versions because you only need to install a new version like every five years. You can install more frequently because there’s new LTS version every two years, but with a non LTS version there’s only official support and bug fixes for nine months. So, we’re gonna go with one of the nine months cycles here and download the latest stable release which is Ubuntu 15.10, this was released maybe 10-15 days ago. We’re gonna download 64 bit because that’s the processor type we’re running. You can either click the download button to download it directly in the browser, or you can click alternative downloads & torrents to view what other type of other files you can download. Now, if you’re running on a really super fast internet connection it doesn’t really make a difference. The in browser download is probably going to download just as quickly as a torrent, however if you don’t have an incredible internet connection, a torrent download is going to make a lot of sense. It’s going to download a lot quicker than it would in the browser. Now, I’ve already got my version downloaded, it took about 10-15 minutes, because I have really bad at the moment. Next thing we’re gonna do, we’re not going to install to directly onto our hard drives yet. That’s an awful big commitment to make when you you’re not really familiar with the system. So, we’re gonna do is go to VirtualBox.org, and this is a piece of software that allows us to create virtualized machines, virtual machines are a virtual computer if you want to call it that. This allows us to create different virtual machines, set them up differently, as well as star different operating systems on one. So, when you get to VirtualBox.org there’s a gigantic button here that you cannot miss. Click on that and it’s gonna take you to the download page for VirtualBox. Now, it offers different packages dependent on different operating systems. This is going to be for the host machine, and to put that it clearer terms, the computer that I’m in right now that we can see is running Windows 10, that is the host. So, I need to download VirtualBox 5 for Windows hosts, this link right here, click that it’s gonna start the download. Now, I’ve already got mine downloaded. We’re going to need these in the next few videos, so thanks for watching!
Python 3 Final Project
Enroll in The Complete Python 3 Course: Beginner to Advanced!
Click here to subscribe for more videos like this!
Alright guys, welcome back. We are at the end of the second section for this course which means you guys have a basic understanding of Python. You actually have enough right now to build some basic programs. Now, you might be thinking well, hold on, we didn’t even do that much. That might seem like it’s true but we’ve learned some core principles and concepts here as well as the language syntax, so far. So, we currently know how to create loops like while and if, or while and for loops, we know the if else statement, we know how to create strings and all the different types like Booleans, and numbers, and we also know how to set variables, among some other stuff. So, what we’re going to do right now is for the project for this section we’re going to put most of what we’ve learned in this section and we’re going to build a calculator program. So, I’m going to open up Chrome here and we’re just going to search Python calculator, just to see you know basically how we might write a calculator, so this looks good. So as you can see in the top of the script their defining for functions, one for addition, subtraction, etc, and each one of them is going to take a limit of two numbers and it’s going to return the result of the chosen mathematical equation between the two numbers. So that’s going to be the same for multiply, divide, everything and here’s where the actual program is going to start to output/input. So basically it’s going to say select an operation and it’s going to tell you what each number is equal to, and then it’s going to create a variable called “choice” and it’s going to use an input function which basically allows the user to type something in that hit enter and whatever the types can be stored choice. So this is going to be the prompt, so this is going to print out before the input so basically it’s gonna say enter choice 1, 2, 3, 4 and then whatever the user types after that it’s going to be stored in the variable choice, and then they’re creating two other variables, the first number and the second number, and for each is going to ask you to enter the number. So, first you enter the type of math you’re gonna be doing, and then you enter the first number, and then you enter the second number, and once you enter here what it’s going to do it’s got everything it needs, so it’s going to use an if else statement to determine what your choice was so that it knows what function to call with the two numbers that you’ve put in, which is awesome, and you guys might be really excited to build this. But, we’re actually going to go a few steps further, and the reason is if we open up a calculator you’re probably going to know that I wasn’t asked right off the bat what mathematical operation I want to perform, it just loads up with the number 0, and then I can type a number so let’s say 50, and the mathematical operator which we are going to use multiply, then two, we’re going to enter and we’re going to get a 100. Now with the ending of the math equation here you’ll notice two differences between this program and the Python script in the background there, and that’s that it didn’t quit, and actually we can continue to operate on the result of that first equation. If I want to add 75 I’m going to hit + 75 and hit enter and it’s going to add it to the result. If i want to multiply that by 2 I just hit x 2 and it’s going to multiply by that. So this is a continuous mathematical operation where the Python script allows you to perform one operation and is limited to two numbers, and it’s not very efficient, and I guess very simple. So, that’s good but we’re going to go a little more advanced. So, go ahead and open your IDE. What we’re going to do here is we are going to be using the regex library, so we’re going to import regex, and we’re going to print out the name of our program and it’s going to be called “print(“Our Magical Calculator”)” Now right off the bat we’re going to create two variables, so “previous = 0” and what this is gonna do is the previous variable is going to hold the result of the previously calculated equation, so we’re going to set it to 0 because we haven’t done any math yet, and then we’re going to create a variable called “run = True” You guys can probably guess what this is gonna do. Now, we need to create a loop for our program so we’re going to type “while run”: and we’re just going to call a function called “performMath” Let’s go up here and create a function called “def performMath” So the first thing we need to do is be able to accept input from the user to type in something, so let’s go ahead and type “equation = input(“Enter equation:”” and for now we’re just going to print out whatever they type so “print(“You typed”, equation)” hit save, now let’s run this. So I’m just going to print “Hello World” and it says you’ve typed Hello World, and then it drops back into the prompt. So going to type “Again typing something” and this is going to loop forever because we haven’t created a way to stop it other than, you know, closing the terminal window, or hitting stop right here. So, what we’re going to do now is create a way to end or quit out of this application. So let’s go ahead and “print(“Type ‘quit’ to exit\n”)” so let’s save that, Now what we need to be able to do is if they type “quit” we want to be able to you know actually quit out of the program. So what we need to do is we need access to the run variable in here, so for example let me just do this first. “if equation == ‘quit’:” let’s go ahead and set “run = false” “else:” print out whatever we typed. So go ahead and save and we’re going to run this. So we can type “Hello” and what it’s doing is this we didn’t type in quit so it’s not doing this instead it’s doing this. So let’s type in “quit” it’s not doing anything. So, basically what’s happening here is this is variable scope. Basically, to explain this this is a variable we created the top level of our program, so not defined in any functions or anything. We are in a function here and we’re in an if statement so we’re further into the code and we’ve stated run equals false. Now this is not going to have any effect on this very well it doesn’t have access to it. So, what we need to do first is actually get that global variable into this function. The way we do that is just at the top of the function type “global run” and then the name of the global variable you’re trying to get access to. Let’s go ahead and save and restart. So you’ll see we can still type in stuff but soon as I type “quit” it actually exits. So that’s what we wanted to do. Now, let’s go ahead and restart this. We’re expecting equations to look like this. So, how can we do that? Well, let’s actually how can we do that without creating a limiting set of functions that will perform operations, what if we want it to do this, you know, or what if we wanted to do this? In the script that we just looked at this wouldn’t be possible because we can only use two numbers and they’re each collected in their own variable, So what we’re going to do is we are going to use a built-in function. So actually what I’m going to do is grab access to the previous global variable as well, going to set previous here “previous = equation” then if we go ahead and rerun this, well we see it still says you’ve typed 80+2, or you’ve typed you know whatever the equation was. So we want this to perform math and what we’re going to do is we’re going to use a built-in function called “eval” So let’s go ahead and type that here “previous = eval(equation)” and then let’s save, let’s restart, and you’re going to see that before it prints out the result, or whatever we’ve put in, it’s going to evaluate it. So this is going to be able to perform complex mathematical operations from strings. So we can literally type in “80*100+42-10+78*142” hit enter and it’s going to calculate that up, and it does it in the correct order. So we all know that multiplication happens before addition and the evaluate statement our function actually is aware of that and it does that for us. You might be thinking, well that’s awesome, why don’t you know in those basic calculator examples why don’t they just use the eval function? The reason is because the eval function is actually supposed to be avoided because it can be dangerous. So, let me show you why. I’m going to print out here “print(“Hello World”)” you’ll see what happens is when it evaluates actually if we type in Python code here it’s going to execute that. So, let me go ahead and set “global run” see so we can actually crash it as well. Now this is going to work as long as we assume that our users are going to be performing math equations, but what if they are not? Well, because of this we are actually going to do this. So go ahead and “equation = eval(equation)” is going to be equal to the evaluation of equation. Actually, hold on “previous” Okay, so what we need to do first is perform regex on it, so we want them to only be entering mathematical symbols or numbers, we don’t want them to be able to type anything or to issue commands. So the way we do that is basically let’s create a new variable, actually let’s assign here we’re going to be entering our regex so “equation = re.sub( ‘ [a-zA-Z,.()” “] ‘ , ‘ ‘, equation)” “equation = re.sub( ‘ [a-zA-Z,.()” “] ‘ , ‘ ‘, equation)” So we’re going to remove everything except you know well everything important. Let’s actually go ahead and also remove the colons, we’re going to replace it with nothing, we’re going to do this equation, so we go ahead and show you what I mean. We’re going to rerun this and I’m going to say, “Hello 6 World” and what happens is going to strip everything out of that before it evaluates it, so it’s only going to accept numbers or as you can see you know the plus symbol, sorry, plus right there, let me remove that, alright. There you go. So “5+11×2” is 27 because 11 x 2 is 22 + 5 = 7. So, we’ve already got an awesome calculator but it doesn’t look quite right. So what we’re going to do is we’re basically just going to put an if statement, it’s only going to ask for you to enter equation if there’s no previous. So what we’re going to do is actually “equation = ” “” here, we’re gonna go ahead and say “if previous == 0:” it’s gonna put that otherwise equation is going to be “else:” “equation = input(str(previous))” So let me go ahead and the first time it’s going to ask for an equation, so “4+3” and then it’s is going to drop down and we can go “-1” and you’ll see that it doesn’t quite work. So, what we need to do is we need to tell it if it is, let me separate this here, there. We want to evaluate it separately if there’s a previous result or not. So what we need to do is let’s go ahead and “if previous == 0:” we’re actually going to do this “previous = eval(equation)” which is going to only evaluate whatever we type in. “else: previous = eval((str(previous) + equation)” “else: previous = eval((str(previous) + equation” Go ahead and save, restart, we’re going to go “4+4” equals 8, “-2” is 6, “*10” is going to be 60, and you can see that we’re actually using different types of math on it. So “+5-2+3” is 66. So this is what we want, but let’s just remove where it says you typed because we no longer need that. “3-2” is 1, “+56” and you can see that now we can really get into the math here. You can evem type, let me start that again, so you can perform basically any mathematical operation here, and when you’re done just hit “quit” Now we wanted to give a specific message when it quits, so let’s just drop down here and have it print out “print(“Goodbye, human.”)” Go ahead run it and we type “quit” you’ll see it now says “Goodbye, human.” and then it closes. So this is actually a completely valid program, and it looks a lot different from the other example that we looked at. Now the eval function can be dangerous OK, it very well can be, and that’s why what we’re doing before we evaluate anything is we’re making sure there’s no letters and there’s none of these characters in it, because if there were you know somebody could…let me open up this. I can’t do that, okay. Somebody could you know if they import the system and the OS modules that are included in Python they could end up damaging their system, and so by using regex to remove all that before its evaluated we’re keeping things safe. So thank you guys for joining me and congratulations on finishing the second section of this course. In the next section, in the next bunch of videos, we’re going to be learning more advanced concepts, and we’re going to be developing more complicated programs than this.