Tuesday, May 26, 2015

Python Basics - Chapter 2 - Python Tutorial

Python BasicsIn the previous chapter we just gave you an overview of the Python Programming Language and we really did not get a chance to see of the language works. In chapter 2 of Learning Python, we are going to focus on Python Basics and actually get to practice typing some code. We will explore all of Python’s core data types with just an introduction to each of them. Our main focus in this chapter is cover why and how we would need a certain data type. Later in the tutorials we will really dive deep into each data type offering you even more knowledge.


Data Types To Be Covered


Numbers – 7534, 87432.33


Strings – ‘Hello World!’


List – [ 1, 89, 45, 5]

Dictionaries – ‘dog': ‘Maggie’, ‘cat': ‘Missy’


Tuples – (‘Tom’, ‘John’)


and more


Python Basics Tutorials List


  1. Assign a Variable in Python

  2. Python Numbers

  3. Python Strings

  4. Python List

  5. Python Dictionaries

  6. Python Tuples

  7. How To Install Sublime Text on Mac OS X

  8. How To Install Sublime Text on Windows

Mac OS X Terminal Commands - Getting Started - Python Tutorial

Mac OS X Terminal CommandsWhen it comes to learning Python there are several other tools you will need to learn as well to make you full fledge Python programmer. In today’s tutorial we will focus on Mac OS X Terminal Commands which we will need to know since we will spend a good amount of time in the Terminal.  Some of you that were around when computers only took commands from command line maybe thinking why are we going back in history but the truth is if you are familiar with the terminal you will be able to make things happen faster and easier than the graphical interface will allow you.


What Is The Terminal?


The terminal is an application that gives you ability to command your computer to perform a certain task by typing in a short command. When using the terminal, you are giving your computer a direct command similar to what some software would do if you were using software to perform the task. The terminal application is the same as back in the day when you would have to type in the command line for certain commands to put a game on your computer or to get the computer to do a simple task. The reason why the terminal is still available in the graphical user interface era is because it is one of the most powerful tools your computer has.


How to Open The Terminal?


The terminal application is located in the applications folder > utilities > terminal. We can either open the terminal through finder or we can be quicker or lazier however you want to look at and press command + space bar which opens spotlight and then we can type in the terminal.


How to Open The Terminal?
Command + Spacebar then type terminal

 


I suggest that you then pin your terminal to your dock so we can be even lazier and just click on the terminal as we go through our Python tutorials.


Entering The Terminal


Now that we have the terminal open.  You will not see much but your terminal will look a bit different than mine.


Open Terminal


Our commands start after the $ symbol.  In this tutorial, we are going show you the $ symbol in our examples since that symbol is universal but do not type it into your terminal when following along with us. Let’s get started with some basic Mac OS X terminal commands that we will be using in our Python tutorials.


Print Working Directory


pwd – Print working directory gives the location of the directory we are currently in.  This is a good way to find out where you are currently at within your files.


$ pwd
/Users/Tommy/desktop

List Information About File


ls – List information about file gives us all the files and folders in the containing folder.


$ ls
comments.py python wizardtut.py
django videos
projects web developement notes

Change Directory


cd – Change directory gives us the ability to navigate through our folders and files.


$ ls
Applications Downloads Pictures
Creative Cloud Files Library Public
Desktop Movies
Documents Music

Thomass-MBP:~ Tommy$ cd desktop

Thomass-MBP:desktop Tommy$

cd /foldername/filename – Move multiple directories at once.


$ cd desktop/python
Thomass-MBP:python Tommy$

cd .. – Move up to parent directory


python Tommy$ cd ..
Thomass-MBP:desktop Tommy$

cd ../.. – Move up to directories


Thomass-MBP:python Tommy$ cd ../..
Thomass-MBP:~ Tommy$

Create New Folder


mkdir – We can create a new folder using this command.


Thomass-MBP:desktop Tommy$ mkdir learnPython
Thomass-MBP:desktop Tommy$ cd learnPython
Thomass-MBP:learnPython Tommy$

Create File


touch – We can use this command to create a file


Thomass-MBP:desktop Tommy$ touch manage.py
Thomass-MBP:desktop Tommy$ ls
django projects web developement notes
learnPython python wizardtut.py
manage.py videos

Remove Files


rm – This command gives us the ability to remove files


Thomass-MBP:desktop Tommy$ ls
comments.py projects web developement notes
django python wizardtut.py
learnPython videos
Thomass-MBP:desktop Tommy$ rm comments.py
Thomass-MBP:desktop Tommy$ ls
django python wizardtut.py
learnPython videos
projects web developement notes
Thomass-MBP:desktop Tommy$

Remove Folder


rmdir – This command gives the ability to remove folders


Thomass-MBP:desktop Tommy$ ls
django python web developement notes
learnPython test wizardtut.py
projects videos
Thomass-MBP:desktop Tommy$ rmdir test
Thomass-MBP:desktop Tommy$ ls
django python wizardtut.py
learnPython videos
projects web developement notes

Make Computer Talk


say – This will change your text into audio.  This has nothing to do with our Python tutorials but I think it is fun and wanted to share it.


Thomass-MBP:desktop Tommy$ say "Learn Python Tutorial is the best Tutorial Site"

Conclusion of Mac OS X Terminal Commands


Now that we have covered some of the basic Mac OS X Terminal Commands we can move on with our Python tutorials.  Theses are only the basics if you want to learn more there are several resources on the internet do not forget to check them out. The commands that we covered in this tutorial will help you through the Python tutorials and if any others come up during the tutorials I will remember to share them.



Monday, May 25, 2015

Install Python 3 on Windows - Getting Started - Python Tutorial

Install Python 3 on WindowsIn this tutorial, we are going to look at how to install Python 3 on a Windows operating system. Unlike Mac, Windows has no default Python software installed on its computers. When we install Python on the Windows computer this will be the only Python available. I apologize that I do not have screenshots but for some reason my wife’s laptop will not take screen shots so if you need more help check out our video tutorial.


Download Python 3


Step 1 – Visit http://python.org this is the primary site for the Python Programming Language. If this is the first time you have visited the Python website after you’re done with this tutorial I suggest that you cruise their website. They have so much great information.


Step 2 – On the main menu hover over Downloads on the right side of the drop down click on Python 3.4.X. X will be a number currently at this time of this tutorial the current version is Python 3.4.2. As long as you click on Python 3 you are ready to go. Download will begin.


Install Python 3 on Windows


Step 1 – Locate your download.  Most likely in your downloads folder or if you use Google chrome it will be on the bottom of the browser.


Step 2 – Open File – Security Warning may open click on the run button.


Step 3 – Select whether to set up Python 3.4.X for all users on this computer.  Your choice here how you wish to install the software for all users or just for you. Then click next.


Step 4 – The Select Destination Directory I suggest that you leave it as current unless you know what you are doing. Then click next. If you change the location Python may not work on your computer.


Step 5 – Customize Python 3.4.X. Leave everything as is but scroll down to “Add python.exe to Path” click on the button and select “Entire feature will be installed on local hard drive” then click next.


Step 6 – The installation process will start. You may get a message “Do you want to allow the following program to install software on your computer” click yes.


Step 7 – You will see a screen that says Complete Python 3.4.X Installer click finish.


Test The Installation


Step 1 – Click on the start button on the bottom left hand corner


Step 2 – In the search type cmd this opens command prompt on Windows and hit enter


Step 3 – When your command prompt opens type “python” no quotes.


You should see the following in your command prompt.


C:\python
Python 3.4.2 (v3.4.2:ab2c023a9432)
Type "help", "copyright", "credits" or "license" for more information.
>>>

Yours should look similar to this. Please take notice of the Python 3.4.2 and below that >>> this means you’re in the interpreter.


If you get an error here please refer to the above video I will describe how to fix the issue. Try restarting your computer and if that doesn’t work the usual suspect when it comes to Python and Windows is the path and I will describe how to access your variables in your path and make the need changes.


Step 4 – Exit the interpreter using exit() or quit()


Awesome you have install Python 3 on your Windows computer.


Windows users for these tutorials I use a Mac so there is a couple differences I want you to be aware of.


  • When I say terminal that means Command Prompt to you

  • When I say open Python interpreter using python3 and means you use Python

  • When I say exit the interpreter using control + d that will not work for windows so will need to use exit() or quit() exit interpreter.

Other than those few issues above there really is no other differences. If you come across one please let us know since we use Macs here, but we want you Windows users to be able to follow a long as well.



Interpreter - Python Tutorial


An interpreter is a program that executes instructions which are normally in a coding language and are given by the user or by another program that has not been compiled into machine language yet.



Sunday, May 24, 2015

Terminal - Python Tutorial

terminalThe terminal is a program that is included on the Mac OS X. The terminal provides a line interface that controls the UNIX based operating system. When using Python on a Mac we access the terminal very often to make commands to the Python software. 


To access the terminal on a Mac:


Via Spotlight – command + spacebar or click on magnifying class at the top screen to open spotlight. Once spotlight is open then type “terminal” to open the application.


Via Finder – applications > utilities > then terminal



Install Python 3 On Mac OS X - Getting Started - Python Tutorial

Install Python 3 On Mac OS XBefore we can get started with our Python tutorials we need to install Python 3 on Mac OS X. Python comes as a software package available for the Mac operating system and installation is pretty straight forward. Python 2.7 is already on your Mac but in this tutorial series, we are focusing on Python 3 since this version of Python is not installed we need to install it on the Mac. Follow this tutorial step by step when setting up Python 3.


Find Python 2 First


I would like you to find Python 2 first.  We are only doing that to show you how to access Python 2 in your system. You will do almost the same steps to access version 3.  You may also want to find out how access version 2.7 in future to work in this version. Do not delete the default version on your computer this will cause all types of problems since some of the Mac’s default software uses version 2.7 to run applications.


Step 1 – Access Your Terminal


We will be doing a lot work in terminal throughout this tutorial series so this is an important step. To access the terminal on a Mac you have several options.


Via Spotlight – We can find the terminal via the spotlight option on the Mac to do this push command + space bar at the same time or go to top of your screen and click on magnifying glass.


mac spot light
Mac Spotlight

Now that we have the spotlight open now we simply type in “terminal”.


spotlight with terminal


Simply hit enter and your terminal will open.


Mac Terminal


There you go there is your terminal.  Your terminal may seem sort of different. That is all right as long as we got it open.


Via the finder – Now opening the terminal via the finder takes longer, but it’s good to know where it is located in your finder. Open finder > applications > Utilities > Terminal. There you go the terminal is open but easier to open via spotlight using command + space bar.


Optional Add Terminal to Dock – I add the terminal to the dock since I use it everyday this is optional for you, but if you are going to follow a long in this tutorial I suggest adding the terminal to your dock. To add the terminal to your dock right click terminal in the dock then go to options > click keep in dock.


Step 2 – Access Python 2


Now that we have the terminal open let’s access Python 2 we do this by simple typing “python” into the terminal and pressing the return key.


#Your layout may look different especially before the dollar sign 

Thomass-MBP:~ Tommy$

#Now enter "python"

Thomass-MBP:~ Tommy$ python

#Hit enter

#Now you should see something similar to this
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

#If you see this then you have accessed Python Interpreter

If you did not get your Python 2 interpreter open then please let us know via the comments below or answers section in the main menu.  We can look into why you were not able to access your Python 2 interpreter. Now that you were able to access the Python 2 interpreter lets exit the interpreter by typing quit() or exit() or control + d. When you exit your terminal should not show >>> that is how you know you have properly exited the interpreter.


Install Python 3 On Mac OS X


We can now install Python 3 on Mac OS X.  Please follow the steps exactly, so we do not have any issues installing Python 3.


Step 1 – Visit http://python.org this is where we can download the Python 3 software.


Step 1 - visit http://python.org
Step 1 – Visit http://python.org

 


 Step 2 – Hover over downloads on Python.org home page.


Hover over downloads on Python.org
Hover over downloads on Python.org

Step 3 – Click on Python 3.4.2 button and Python 3 will download


Click on Python 3.4.2 and Python 3 will Download
Click on Python 3.4.2 and Python 3 will Download

Step 4 – Just open the download where you have download the software. Yours maybe different than mine, but most likely in your downloads file. We will refer to the screenshot below and press continue.


Open Python Download
Open Python Download

 


Step 5 – Now we are on a screen that says important information. You can read this if you like if not then go ahead and press continue.


Important Information Page
Important Information Page

 


Step 6 – Now we are on a screen that says the software License Agreement. Once again you can read this if you like and when done click continue. Then a screen will pop up click agree if you agree with the Software License Agreement.Software License Agreement


Software License Agreement


 


Agree to Software License Agreement
Agree to Software License Agreement

 


Step 7 – Next page we come to is install location page. Do not change the location unless you understand what you are doing. Just press install to install in the current location.


Install Location
Install Location

Step 8 – When you press install a window will popup and ask you to enter your password please do so.


Enter Password
Enter Password

Step 9 – Python will start the install process.


Python will Start Install Process
Python will Start Install Process

 


Step 10 – When installation is complete press close button.


Installation Complete Press Close
Installation Complete Press Close

 


Now Python is installed on your computer. We will now check the installation to ensure that it installed properly. To check the installation of Python follow the next couple of steps.


Check Python 3 Installation


Step 1 – Open the terminal using the steps in the beginning of this tutorial.


Open Terminal
Open Terminal

Step 2 – Now we type “python3″ to open our Python 3 Interpreter and press Return.


Type "python3" Press Return
Type “python3″ Press Return

 


Step 3 – We should see something very similar to the following screenshot.


You Should See The Following
You Should See The Following

 


If you see something very similar to the above screenshot especially Python 3.4.X. X being the latest version so this may change just a bit. If you see this, then you have successfully complete the Install Python 3 on Mac OS X tutorial. If you did not get this or got some errors please leave a comment below or in the answers section of this website so we can help you get Python 3 on your Mac.


The install Python 3 on Mac OS X process is very simple but if your operating system is configured differently than we could run into some issues. If you have any questions about the installation process, please ask we are here to help you a long.



Saturday, May 23, 2015

Python Software Foundation - Python Tutorial

Python Software FoundationThe Python Software Foundation is the non-profit organization in charge of developing Python. The Python Software Foundation was established in 2001 to support the Python Programming Language. You can visit the Python website http://python.org to get more information on the Python Software Foundation.



Guido Van Rossum - Python Tutorial

guido van rossumGuido Van Rossum is a dutch computer programmer who developed the Python programming language. Mr. Van Rossum now oversees the development of Python.  He has been employed by Google where he spent most of time developing Python.  He now works for Dropbox.



Friday, May 22, 2015

Python Programming Language - Python Tutorial

Python Programming LanguagePython Programming Language is a very powerful user friendly general purpose programming language. The development of Python had one goal in mind making it user friendly and they did this by designing the language to be easy to learn, read and use. Python was originally developed by a man named Guido Van Rossum who created Python as a hobby. You can get more information about the Python Programming language by visiting Python’s website at http://python.org



History Of The Python Programming Language - Getting Started - Python Tutorial

History Of The Python Programming LanguageHistory Of The Python Programming Language


Python came about when a man named Guido Van Rossum was looking for a hobby during Christmas break back in 1989.  He just wanted to write an interpreter for a scripting language which he has been thinking about for sometime. Over that break, he creates a scripting language which he later named it Python after the Monty Python’s Flying Circus which he was a large fan of.


First Public Release


Van Rossum first released Python in 1991 for public to use. The Python language did not really can ground with the public till a forum was created to discuss the language in 1994.


in 1994


Version 1.0 was released in 1994 right when Python started to gain traction with some followers. One of the main focuses of this release was making the language easy to use.


in 2000


Version 2.0 was released in 2000 giving the language the ability to garbage collect which is a form automatic memory management.


In 2001


Python formed a non-profit organization called Python Software Foundation and version 2.1 was released.


in 2008 


Python 3 was released to the public.  Python 3 was designed to reduce the multiple ways to do something and try to limit it to only one correct way to code.  This this idea it has made Python even easier to learn and write.


Conclusion


This was a just a brief overview of the History Of The Python Programming Language there was obviously a lot more going on over the years.  My main goal here was to just to show you how the language came about and it progressed through the years.


We will be focusing on Python 3 in our tutorials.



Thursday, May 21, 2015

Why Should You Learn Python - Getting Started - Python Tutorial

Why Should You Learn PythonWhy Should You Learn Python


Why should you learn Python? Well the easiest answer to that question is because it is absolutely amazing! That may be not good enough answer to persuade you to learn Python. So in this tutorial we are going to try to convince you to learn Python over other programming languages. There is no simple explanation why over a million programmers have chosen to use Python as their go to programming language in their projects. Below you will find several reasons why Python has been chosen time and time again.


Powerful


Why should you learn Python? I asked this question again under the powerful headline because this will show you why Python is chosen over and over.  Python is powerful enough for Google and NASA.  That is right Python is used by two of biggest technology companies in world. How about some light reading about why NASA has chosen Python https://www.python.org/about/success/usa/ Conviced yet? Ok how about some more reasons check these out https://www.python.org/about/success/


Readable


The Python language is easy to read when compared to other languages. The Python code can even be read by people who never saw code before. Reading Python code is like reading a english language.  If you can read than you can read the code. Once you’re able to read the code learning how to write the code is very simple with some practice. Practice brings on memorization of how to write the code and limits the need for reference manuals and hours of research like some other languages require.  Python has a pretty simple syntax which is why it is so simple to read.


Reusable


The code you have written or other, programmers have written can be reused in your programs with ease. Python was designed so you do not have to repeat yourself(rewrite the code). Python supports object oriented and functional programming which gives us the ability to type the code once and call it when needed.


Productivity


It takes less code to write programs in Python than some other popular programming languages out there. The less code you need to write to make things happen in your software means the more time you have to spend doing other things you love.


Packages


Python offers software packages which are easy imported into your software so you do not have to write code that has been already written by your fellow Python programmers. This again revisits the concept do not repeat yourself which means less work for us. As of today, there are 55,000 packages available for you to use in your programs. If you would want to check out the Python Package repository visit https://pypi.python.org/pypi. We will show how to import packages in our tutorials.


Support


The Python programming language has a lot of support across the internet. If you Google a Python question then you will get hundreds of answers to your question.  A word of warning though make sure you find a quality source to constantly refer to like our site.  Some sources across the web could confuse you more than help you. When I have a question I always turn to the Python documentation at https://www.python.org/ this is the main source for the Python Programming language.


It is Just Flat Out Fun To Work With


I have worked with PHP, Ruby, C and Python, but Python is by far my favorite. It has a great deal to do with the ease of use and the support that the language has which keeps me so interested in Python. I quickly noticed how much more I liked Python over other languages after a couple of days of working with the language.  I am not bashing any other languages I just enjoy this language more than the others.  You may disagree with me and that is fine everyone has their preference.


I hope we answered your question why should you learn Python? This language seems to have a lot of great aspects but it also has only one downside that I have noticed and that is speed as computers get faster it is tougher to see the speed issue so I will not discuss that anymore. If you have any questions please leave us a comment below so we can help you out.


 


 



Getting Started With Python - Chapter 1 - Python Tutorial

Getting Started With PythonGetting Started with Python


This is an introduction to chapter 1 of our Python Tutorials.  Each section of our Python tutorials are broken down into chapters for better navigation and awareness of your progression throughout our tutorial series.


In chapter 1 we are going to give you a background on the Python Programming Language. We will look at the history of the language, discover why you should learn the language and even talk about more resources to help your learn how to program with this amazing programming language.


Chapter 1 Contents


  1. Why Should You Learn Python?

  2. History of The Python Programming Language

  3. Install Python 3 On Mac OS X 

  4. Install Python 3 Windows

  5. Mac OS X Terminal Commands

When you’ve completed getting started with Python move on to chapter 2 of our website to continue learning.


 


 



Wednesday, May 20, 2015

Introduction to Learn Python Tutorial Website - Python Tutorial

Learn Python Tutorial


Welcome to Learn Python Tutorial’s website. I hope you’re ready to take a journey to becoming a professional programmer. This website was designed for people whom never even looked the code of a program before.  If you have no technical background or programming experience you will be in a position to follow right along with these Python tutorials. If you have the time, courage and the discipline you will succeed in becoming a professional Python programmer with learn Python Tutorial.


 


What this Website Is


This website was designed to be the go to source for learning the Python language. We will cover the Python Language itself and some of Python Standard Libraries, applications, and Web Frameworks more specifically Django. To be more clear we posted some bullet points below about what this website is.


  • This website is a Python Tutorial Website

  • This website is designed to be used as a Python Reference

  • This website is a in depth look into how to program with Python not a overview

  • This website is completely FREE!


What this Website Is Not


This website is not a short tutorial to Python Programming Language or just an overview of the language.  As we did above we will gave you some bullet points to be more clear about what this website is not.


  • This website is not a short tutorial

  • This website is not a overview of Python Language

  • This website does not charge you money to learn Python

  • This website is not affiliated with the founders or developers of the Python language


How our Tutorials are Laid Out


Our tutorials are set forth in a specific order for almost every tutorial. Below you will see the order of how each and every one of our Python tutorials will be laid out throughout this course. Some of tutorials layouts may be changed based on the subject, but it will most likely always be in this order.


  1. Video Tutorial

  2. Overview of Tutorial

  3. Explanation why and how to use the subject being covered.

  4. Examples of the subject being covered

  5. Quiz on Subject

  6. Comments or Questions about Tutorial


How Often Does Learn Python Tutorial Website Post Tutorials


Learn Python Tutorial post new tutorials almost everyday.  We try our hardest to get out new tutorials every day but sometimes that is not possible but we will go no more than three days without a new Python tutorial.


 


What We Expects From Our Students


We do not expect much from our students except to try very hard to succeed. If you do not succeed then we did not succeed. We would like to encourage you to ask questions in the comments section of the tutorials so we can help you better understand the Python Programming Language.


When you interact with us or other, students you help us improve our tutorials and help yourself learn the language better. DO NOT BE SHY.  There are no stupid questions. Your input matters to us and other students.


Conclusion


We hope you enjoy our Python Tutorials if you have questions speak up and if you want to bash us go right ahead we are taking our tutorials to new level and some of you may not like it but for those who follow a long will be in a better position than the hatters.

If you have a suggestion please let us know. We want to make this site the best tutorial website but without your input about Learn Python Tutorial we will not be able to improve our tutorials.


 



Tuesday, May 19, 2015

Less Than or Equal to


Less Than or Equal to <=


The less than or equal to <= comparison operator checks if the object on left is less than or equal to the object on the right and if it is then Python returns True.  If the object on the left is greater than the right then Python will return False.


Less Than or Equal to <= Examples


#Less Than or Equal to <=

>>> 4 <= 5
True
>>> 5 <= 5
True
>>> 6 <= 5
False

If you have any questions about less than or equal to <= leave a comment below so we can assist you.



Greater Than or Equal to >= - Python Tutorial


Greater Than or Equal to >=


The Greater Than or Equal to >= will check if the left side is greater or equal to the right side if it is then Python will return True and if left side is less than the right then Python will return False


Greater Than or Equal to >= Examples


= Examples" >#Great Than or Equal to >= Examples

>>> 7 >= 5
True
>>> 4 >= 5
False

If you have any questions about Greater Than or Equal to >= leave a comment below so we can help you better understand this comparison operator.



Monday, May 18, 2015

Not Equal != - Python Tutorial

not equal !=



 


Not Equal !=


The not equal to symbol will compare the left side to the right side. If the object on the left is not equal to the object on right then Python will return True and if they are equal to each other then Python will return False


Not Equal != Examples


#Not Equal != Examples

>>> 5 != 4
True
>>> 5 != 5
False

If you have any questions about not equal != leave a comment below.



Equal To == - Python Tutorial

Equal To ==



 


Equal To ==


Equal to symbol == compares the object on the left to the object on the right if they are equal to one another than Python will return True and if the left is not equal to the right than Python will return False.


Equal To == Examples


#Equal To == Examples

>>> 5 == 5
True
>>> 5 == 6
False

If you have any questions about equal to == leave a comment below.


 



Sunday, May 17, 2015

Greater Than > - Python Tutorial

>



 


The > simple is used as a comparison operator in Python.  If the object on the left of the > is greater than the object on the right then Python will return True.  If the object on the left of > is less than the object on right then Python will return False.


> Examples


 Examples" ># > Examples

>>> 2 > 1
True
>>> 1 > 2
False

If you have any questions about the Python > leave a comment below.



Saturday, May 16, 2015

Python Comparison Operators - Python Numbers - Python Tutorial

Python Comparison OperatorsPython Comparison Operators


In the previous Python tutorial, we looked at booleans now we can use some Python comparison operators to get a boolean returned to us.  Python comparison operators are a vital part of programming with Python. We use the comparison operators to compare objects and tell the program to do something when a certain return happens.  We can compare if an object is greater than, less than, equal to, not equal to, greater than and equal to or less than and equal to.


Single Comparison Operators


== Equal Or Not Equal


The == symbols will check if the left side is equal to the right if so Python will return True if not then we get False. Do not make the mistake of using a single equal symbol like =, you will get an error or assign a variable.


#== Equal Or Not Equal

>>> 6 == 6
True
>>> 6 == 7
False

!= Not Equal or Equal


The != symbols will check if the left side is not equal to the right side if so Python will return True but if the left is equal to right then we will get False. This is opposite of the == operator.


#!= Not Equal or Equal

>>> 6 != 8
True
>>> 5 != 5
False

> Left is Greater Than Right


The > symbol will check if the left side is greater than the right.  If the left is greater Python will return True and if left is less Python will return False.


 Left is Greater Than Right" ># > Left is Greater Than Right

>>> 6 > 5
True
>>> 6 > 8
False

< Right is Greater Than Right 


The < symbol will check if the right side is greater than the left.  If the right if greater Python will return True and if the right is less Python will return false.


# < Right is Greater Than Right 

>>> 5 < 6
True
>>> 6 < 5
False

>= Left is Greater Than or Equal to Right


The >= symbols check if the left side is either greater or equal to the right side.  If the left is greater or equal to right then Python returns True if left side is less than right then Python returns False.


= Left is Greater Than or Equal to Right" ># >= Left is Greater Than or Equal to Right

>>> 7 >= 6
True
>>> 6 >= 6
True
>>> 5 >= 6
False

<= Right is Greater Than or Equal To Left


The <= right is greater than or equal to the left. If the right is greater or equal to the left then Python will return True if right side is less than Python will return False.


# <= Right is Greater or Equal To Left

>>> 6 <= 7
True
>>> 6 <= 6
True
>>> 6 <= 5
False

Chained Comparisons


Now that we have learned to use Comparison Operators in Python we can actually compare larger amounts of data using something called chained comparisons.  We will show you a bunch of examples below but they are pretty straight forward if you understand Comparision Operators so we will not explain each one.


#Chained Comparison Operators

>>> 4 < 6 < 8
True
>>> 7 > 4 == 4
True
>>> 9 != 7 != 6
True
>>> 10 > 8 > 6 > 4 > 2 > 0
True

>>> 5 > 2 and 7 < 10
True
>>> 6 == 6 or 7 != 5
True

Conclusion


Comparison operators are very simple to use and are effective in programming.  You will become very familiar to comparison operators as you move on in your Python programming career.  If you have any questions about Python comparison operators let us know via comment below.



Booleans In Python - Python Numbers - Python Tutorial

booleans in pythonBooleans In Python


In this Python tutorial, we are going to look at booleans in Python. Booleans are sometimes called truth statements in programming. Booleans are returned only a True or False.  You may be asking why we are covering booleans in the numbers section our Python tutorial. Booleans are indeed part of the integer family. A True boolean is equal to 1 and a False boolean is equal to 0.


Boolean Examples in Python


We will be checking out examples of booleans. Some of the methods, operators or functions may have not been covered yet in our tutorial series.  Just follow along we are going to get to all these very shortly. All these examples will be performed in our Python interpreter.


#boolean Examples in Python

#Boolean Operations
>>> False or True
True
>>> True or False
True
>>> False or False
False
>>> True or True
True
>>> True and False
False
>>> True and True
True
>>> False and False
False
>>> not False
True

#Comparison Operators
>>> 7 < 9
True
>>> 8 > 8
False
>>> 8 != 9
True
>>> 8 == 8
True
>>> 8 <= 9
True


Proof That Booleans are Integers


#Proof That Booleans are Integers

>>> True + False
1
>>> True * False
0
>>> True ** 8
1
>>> type(True)
<class 'bool'>
>>> a = True + False
>>> type(a)
<class 'int'>

We will do a lot of work with Python booleans over the next couple of Python tutorials. If you have any questions about booleans in Python leave, a comment below so we can help you.


 



Friday, May 15, 2015

str() - Python Tutorial

str() built-in function



 


str() Built-in Function


str() is a built-in function in Python that will convert an other type like a integer, float, list, tuple and so on to a string.


Str() Syntax


syntax(argument)


The argument can be a integer, floating point number, list, tuple, dictionary, file, and so on.  The argument will be converted to a string.


str() Built-in Function Examples


#Str() Built-in Function

>>> str(6)
'6'
>>> str(7.6)
'7.6'
>>> str((6,75,9))
'(6, 75, 9)'
>>> str('cat': 'mary', 'dog': 'maggie')
"'cat': 'mary', 'dog': 'maggie'"

If you have any questions about the str() built-in function leave a comment below and we will do our best to assist you.


float() - Python Tutorial

float() built-in function in python



 


Float() Built-in Function In Python


The float() built-in function converts integers and strings to floating point numbers.  This basic function simply just changes the type of object to a floating point number type in Python.


Float() Syntax


float(argument)


The argument can be a integer or string.  You can also include a float but it will do nothing to the floating point number. If you call the float() function on a integer the when be convert to float which it will contain a decimal and a zero.


Float() Examples


#float examples

>>> float(1)
1.0
>>> float("6")
6.0
>>> float("5.6")
5.6

If you have any questions about the float() built-in function leave a comment below and we will assist you.


 



Thursday, May 14, 2015

int() - Python Tutorial

int() in python



 


int() Python Built-in Function


int() is a built-in function that will convert a floating point number or string to an integer type. If a user or our program returns a string or a float we can use the int() function to convert the number to integer. The int() function rounds the float down to the floor check the examples below.


int() Built-in Function Example


#int() Examples

#int() example
>>> int(8.7)
8

#int() example
>>> int(9.876)
9

#int() example
>>> int(5.3)
5

#int() example
>>> int(6)
6

#int() example
>>> int("5677")
5677

#This does not work we can not convert a float string but check next example
>>> int("5.98")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '5.98'

#The fix to above example
>>> int(float("5.98"))
5

If you have any questions about int() built-in function leave a comment below.


 



How to Convert Number Types in Python - Python Numbers - Python Tutorial

How to Convert Number Types in PythonHow To Convert Number Types in Python


In this Python tutorial, we are going to explore how to convert number types in Python. When coding sometimes we need in order to convert our current integer to a float or our current float to integer. We can also convert strings to either integers or floating point numbers.  Python has a built-in function that will give us the ability to do this.


Int() Built-in Function


The int() built-in function gives the ability to convert either a floating point number to an integer or convert a string to an integer. The int() function will always round down when converting floating point numbers. We also cannot convert floating point number strings to integers but we can do it we will look at that later in this tutorial. Let’s take a closer look at some int() examples.


#int() built-in function

#convert floats to integers
>>> int(4.5)
4
>>> int(1.45643)
1

#convert string integers to integers
>>> int("5")
5
>>> int("9")
9


Float() Built-in Function


The float() built-in function gives us the ability to convert integers to floating point numbers and convert strings to floating point numbers let’s take a closer look at this example.


#float() built-in function

#Convert integer to float
>>> float(6)
6.0

#convert integer to float
>>> float(-78)
-78.0

#convert integer in a string to a floating point number
>>> float("5")
5.0

#convert a floating point number string to a actual floating point number
>>> float("6.7")
6.7

Converting a String Floating Point Number To A Real Integer


#just using int will not work
>>> int("6.7")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '6.7'

#first convert to float then to integer
>>> int(float("6.7"))
6

Checking The Type Of An Object


We can also use the type() built-in function to check the type of an object.


#type()

>>> type(6)
<class 'int'>
>>> type(())
<class 'tuple'>
>>> type(7.6)
<class 'float'>
>>> type("")
<class 'str'>

Conclusion


 


In this Python tutorial, we took a look at How to Convert Number Types in Python. These built-in functions help us with our code so we do not have to build our own function to convert the number types. If you have any questions about this tutorial please leave a comment below.



Wednesday, May 13, 2015

Manually Adjust The Operator Precedence - Python Numbers - Python Tutorial

Manually Adjust the Operator PrecedenceManually Adjust The Operator Precedence


In the previous Python tutorial, we took a look at how Python evaluates equations using the operator precedence. In this Python tutorial, we are going to throw out all the information you learned in the previous tutorial and show you how you can control the operator precedence with parentheses in your equations.


Python will evaluate parentheses first then default to the operator precedence. This gives us the ability to adjust how Python will run an equation and gives us more control over our mathematical equations in our programs.


The Operator Precedence


A little review how the operator precedence is evaluated in Python.


  1. **

  2. *, /, %, //

  3. +, -

In the default operator precedence exponent(**) will always run before any other operator.  Then multiplication(*), true division(/), modulo(%), and floor division(//) will run after the exponent(**).  Then finally addition(+) and subtraction(-) will run.


If an equation contains operators in the precedence like addition(+) and subtraction(-) then the equation will run left to right.


Manually Adjust The Operator Precedence


With Python we have the ability to manually adjust the operator precedence using parentheses which Python will run first then go to the default operator precedence after running the equation in the parentheses. This option gives us more control over our code and helps control flow of our math equations.


Manually Adjust The Operator Precedence Examples


#Manually Adjust The Operator Precedence Examples

#Default Operator Precedence Exponent first
>>> 2 ** 2 + 2
6

#Still runs exponent first
>>> 2 + 2 ** 2
6

#runs addition
>>> (2 + 2) ** 2
16

#runs left to right
>>> 3 * 8 / 2
12.0

#runs division first
>>> 3 * (8 / 2)
12.0

#runs division first
>>> 6 * (7 / 4)
10.5

#test the equation
>>> 7/4
1.75

#test the equation
>>> 1.75 * 6
10.5

#Python runs multiplication first
>>> 6 + 5 - 3 + 4 * 10
48

#Python runs addition and subtraction first
>>> (6 + 5 - 3 +4) * 10
120

Conclusion 


In this tutorial, we learned how to Manually Adjust the Operator Precedence which gives us more control over our code and gives the flexibility to write quality programs. It is important to know that Python will default to its operator precedence after running the parentheses.


If you have any questions leave a comment below and we will do our best to help you out.


 


 



round() - Python Tutorial


round() is a build-in function in the Python Programming Language which gives us the ability to round a floating point number to the closest multiple of 10. It is important to understand that round() function takes a floating point number which has been convert from a fraction so sometimes the round() may return some numbers a different than you expect.


round() Syntax


round(floating point number, numbers after the decimal)


Round() only takes floating point numbers which is our first argument and the second argument is how many numbers positions do you want after the decimal point. If you do not provide a second argument python will return a integer type number as the default.


round() Examples


#round() Examples

#round() with no second argument
>>> round(1.7)
2

#round() with an second argument of 1
>>> round(1.76, 1)
1.8

#round() example with an second argument of 4
>>> round(1.56787, 4)
1.5679

Weird Round() Returns


round(0.5) – returns 0 but we would expect this to return 1


round(2.675, 2) - returns 2.67 but in reality it should be 2.68.  Python returns 2.67 because this number is convert to a fraction and then converted back from a fraction and the conversion is not exact the actual return for 2.67 is 2.67499999999999982236431605997495353221893310546875



Tuesday, May 12, 2015

deallocation - Python Tutorial

Deallocation is the process Python uses to remove reserved memory. This process is done by Python’s memory management process.



allocation - Python Tutorial

Allocation is how Python distributes space for memory in Python programs.  Allocation is part of the Python memory management process.



Monday, May 11, 2015

Operator Precedence in Python - Python Numbers - Python Tutorial

Operator Precedence in PythonOperator Precedence in Python


In this Python tutorial, we are going to look at operator precedence in Python. We will be focusing on the operators we have already learned like **, *, /, //, %, + and -. It is important to understand what operator will run first.


Operator Precedence


The list below will show which operator has more precedence over the operators.  So the first operator in the list will run before the second operator below.


  1. ** – Exponent

  2. *, /, %, // – Multiplication, true division, modulo, floor division.  In this case if these operators where in the same equation then the equation would run left to right.

  3. +, – Addition and Subtraction are the last operators to run.

Operator Precedence Examples


Let’s look at some examples and figure out which operator will run in the equation. The order in which the operators run could have some serious effects on your results.


Exponent and Multiplication


Exponent will always run before the multiplication equation. Take a look at the example.


#Exponent and Multiplication

#Exponent Runs First

>>> 2 ** 2 * 2
8

#If multiplication ran first this answer would be 16
>>> 2 * 2 ** 2
8

Exponent and Division


Exponent will always run before a division equation. Take a look at this example.


#Exponent and Division

#exponent runs first
>>> 4 / 2 ** 6
0.0625

#2 ** 6 is 64
>>> 4 / 64
0.0625

Multiplication and Division


In this scenario Python will run the equation from left to right since multiplication and division have the precedence. Take a look at the example below.


#Multiplication and Division

#In this case division is ran first then multiplied by 3
>>> 5 / 4 * 3
3.75

#In this case 3 is multiplied by 4 then divided by 5
>>> 3 * 4 / 5
2.4

Multiplication and Addition


Multiplication will run before an addition equation since multiplication has more precedence over addition. Here is an example.


#Multiplication and Addition

>>> 2 + 4 * 4
18

Addition and Subtraction


In this scenario the equation will run left to right since addition and subtraction are on the same level.


#Addition and Subtraction

>>> 2 + 3 - 5 + 8 - 4 + 2 - 9
-3

Conclusion


In this Python tutorial, we took a look at Operator Precedence in Python it is important to remember which operator will run first because you can end up with different values if you are not paying attention when setting up your equations. In the next Python tutorial, we will look at a way to manually change the order.



User Select Temperature Conversion Python Program – Part 2 - Python Tutorial

User Select Temperature Conversion Python ProgramUser Select Temperature Conversion Python Program – Part 2


In this Python tutorial, we will improve our program we built-in the previous tutorial called user select temperature conversion Python program. This is a great opportunity to see how to work through your program to address issues and limit the amount of time troubleshooting your program after release. Recall that it is always important to trouble shoot your programs over and over before you release it. If you release a program that contains issues in the world, then you will spend more time handling support than you would working on your next project.


Functions and Methods In This Python Tutorial


  • print()

  • input()

  • if statement

  • .lower()

  • .strip()

  • .format()

  • float()

  • round()

  • slice [0]

Issues with our Program


We saw some issues in our first Python program that would have made our program less desirable to our users.  First issue we saw was that the user would have to capitalize celsius or fahrenheit and prior experience, I know users are unlikely to use the shift key when they want a quick answer. Second issue we saw was if the user inputs the wrong command in the code would still run and then return an error which is not good practice if the program fails then the user should know why right away. Issue three if the user spelled fahrenheit or celsius wrong the program would fail that is not the right idea users would be turned off and never use our program. Let’s look at the issues and work through them and fix them


Code From Version 1.0 Of Our Program


#Code From Version 1.0 Of Our Program

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")
userstemp = float(input("What is your temp to be converted. "))

if temp == 'Celsius':
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp == 'Fahrenheit':
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))
else:
print("Whoops Something went wrong")

Fixing The Issues in Version 1.0


We need to fix this program so it runs flawlessly when we release the program to our clients. Our goal is to make the program more user friendly and reliable.


Issue 1


Issue 1 –  The program runs even if the user gives us the wrong command


If the user gives us the wrong command in our second line of code then line third line will still run and then kick back an error.  This is not good practice if the user does something wrong they should be alerted right away.


The Fix


We can fix issue 1 by moving the third line of our code which asks the user to input the current temperature into the if statement. We will now use this line twice once in the if statement and once in the elif statement.This ensures our code will only work when the user inputs the correct command.


The Code 


#issue 1 code

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")


if temp == 'Celsius':
userstemp = float(input("What is your temp to be converted. "))
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp == 'Fahrenheit':
userstemp = float(input("What is your temp to be converted. "))
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))
else:
print("Whoops Something went wrong")

Tip: Any time you make changes to your program I suggest you run the program so you can locate any issues that may arise from the code changes. If the program does not work then you will know the problem code.


Issue 2


Issue 2 – If the user does not capitalize Celsius or Fahrenheit then the program will fail


When the user types in a command in our current code they must capitalize the first letter.  In my prior experience users do not necessarily do so. This will cause the program to fail and this would not be good for our business. User’s would think we build crappy programs and go to our competition which would not be a good idea.


The Fix


We can easily fix this problem using .lower() string method which will make the users input lowercase which will give us the ability to anticipate the user’s input.  If we use the .lower() string method then we need to change our if and elif statements so that our code has celsius and fahrenheit in lowercase so it matches the users input.


The Code


#issue 2 code

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ").lower()

if temp == 'celsius':
userstemp = float(input("What is your temp to be converted. "))
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp == 'fahrenheit':
userstemp = float(input("What is your temp to be converted. "))
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))
else:
print("Whoops Something went wrong")

Issue 3


Issue 3 – If the user uses a space in our code then the code will fail


If the user uses a space in front of the command or after the command then our code will fail and once again we will want to avoid this.


The Fix


To ensure that the user does not use a space in front of command or after the command, we need to use a string method called .strip() this will remove the spaces before and after the command.


The Code


#issue 3 code

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ").lower().strip()

if temp == 'celsius':
userstemp = float(input("What is your temp to be converted. "))
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp == 'fahrenheit':
userstemp = float(input("What is your temp to be converted. "))
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))
else:
print("Whoops Something went wrong")

Issue 4


Issue 4 – If the user spells the command wrong code will fail


If the user misspells celsius or fahrenheit wrong then our code will fail.  We want to think of ways a user could make our code fail and avoid the scenario at all cost.


The Fix


We could use a slice on the user’s input to get just the users first letter. Since the two commands start with different letters, we can avoid spelling mistakes by getting the users first letter and running the code based off that. We indicate a slice with square brackets[ ] and then we put zero in the square brackets which says we want the first letter of the users command.  We will need to change if and elif statements to c and f since we just want the first letter.


The Code


#Issue 4 Code

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ").lower().strip()


if temp[0] == 'c':
userstemp = float(input("What is your temp to be converted. "))
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp[0] == 'f':
userstemp = float(input("What is your temp to be converted. "))
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))
else:
print("Whoops Something went wrong")

Conclusion


We have now updated our program to version 1.1 which is now more user friendly and less likely to break when our clients use our program. I have a tendency to build programs like this I will first build one so I can get the result I want and then I will work my way through the program fixing issues that may arise. I will concentrate on the users experience, program speed and reliability. If we can fix all the issues in our program before we release the program we will live a happy life.


If you have any questions about User Select Temperature Conversion Python Program leave a comment below and we will do our best to help you out.



Sunday, May 10, 2015

User Select Temperature Conversion Python Program - Python Program Tutorial - Python Tutorial

User Select Temperature Conversion Python ProgramUser Select Temperature Conversion Python Program


In this Python tutorial, we are going to show you how to improve our previous two Python programs that we built by adding a feature where the user can select their conversion. We will build a user select temperature conversion Python program. This program will actually combine our previous two programs into one program and make the program more user friendly.


Functions, Methods and Control Statements Used In This Python Tutorial


  • print()

  • input()

  • float()

  • If Statement

  • round()

  • .format()

Python Program Build


Step 1 – Open Text Editor and Save Project


We first have to open our text editor and save the project as usertemp.py.


Step 2 – Welcome Statement


We use a print() statement in this case to return the text ‘Welcome To Our Temp Conversion Program’.


#Welcome Statement

print('Welcome To Our Temp Conversion Program')

Step 3 - Users Conversion Selection


This steps we ask the user which type of temperature conversion they would like to perform. The user will be able to select their type by typing Celsius or Fahrenheit into the command line. We first create a variable called ‘temp’ and assign this variable to the user’s input.  To get the user’s input we use input() and tell them to enter one of two commands.


#Users Conversion Selection

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")

Step 4 – User’s Temperature Input


This step we ask the user for their temperature and assign their input to the variable ‘userstemp’.  Create a variable called ‘userstemp’ and assign it to the users input().


#User's Temperature Input

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")
userstemp = float(input("What is your temp to be converted. "))

Step 5 – Flow Statement “IF Statement”


In this step, we introduce an if statement which will help us return the proper conversion to the user. I know we have not been covered if statements yet which we will cover in full in our Python tutorials shortly. It is good to see some advanced features of the Python programming language as we move along.

First thing we need to do is create the if statement. On the first line of the if statement, we say if the user’s input is equal to celsius then run the code below which is our code from our previous tutorial celsius conversion. If it is not equal to celsius then move on to the next if statement(elif).


#Flow Statement "IF Statement"

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")
userstemp = float(input("What is your temp to be converted. "))

if temp == 'Celsius':
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))

Step 6 – Flow Statement “elif Statement”


In this step, we need to create a elif statement which is part of the if statement. If the previous statement is not true, then the program will skip the code below and move on to our elif statement. For the elif statement we want to see if the user entered ‘Fahrenheit’ if the user entered ‘Fahrenheit’ then our block of code contained in the elif statement will run. This code is similar to our previous Python tutorial where we converted celsius to fahrenheit.


#Flow Statement "elif Statement"

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")
userstemp = float(input("What is your temp to be converted. "))

if temp == 'Celsius':
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp == 'Fahrenheit':
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))

Step 7 – Flow Statement “else”


In the final step of our program we have an else statement.  If the user enters anything other than ‘Celsius’ or ‘Fahrenheit’ the code will run the else statement.  This happen if the user misspells ‘Celsius’ or enters a word we did not request.  The else statement contains a simple print() statement.


#Flow Statement 'else'

print('Welcome To Our Temp Conversion Program')
temp = input("What temp would you like to convert to? Type Celsius or Fahrenheit. ")
userstemp = float(input("What is your temp to be converted. "))

if temp == 'Celsius':
cel = round((userstemp - 32) * 5 / 9, 1)
print("Your temp in Celsius is ".format(cel))
elif temp == 'Fahrenheit':
fah = round(userstemp * 9 / 5 + 32, 1)
print("Your temp in Fahrenheit is ".format(fah))
else:
print("Whoops Something went wrong")

Step 8 – Run The Program


Open your terminal or command prompt. cd into your desktop and type ‘python3 usertemp.py’ this will run your Python program. Try it out to make sure it works if it does that is great if you run into problems check your code with ours. If it does work, then your goal is to break the program. When you break your program, you should take notes how the failures in your code and this is how we know where our code needs to improve.


#Run The Program

Thomass-MBP:desktop Tommy$ python3 userstemp.py
Welcome To Our Temp Conversion Program
What temp would you like to convert to? Type Celsius or Fahrenheit. Fahrenheit
What is your temp to be converted. 26.5
Your temp in Fahrenheit is 79.7

Awesome we created a program that will take a user’s command indicating which type of conversion and then we also will take the temperature that needs to be converted.  If you played around with the program you probably noticed there are some issues we could have if we released this program to the public.


Issues with our program


  1. User must type the proper word with proper capitalization if not we will get an error.

  2. If the user does not enter the conversion properly the program will still ask for the users temperature which will not indicate to the user that they entered the wrong command.

In the next tutorial we will make some changes to the code to we can make it more user friendly and more reliable.


If you have any questions about this Python tutorial building a User Select Temperature Conversion Python program please leave a comment below we are here to help you learn Python.


Source Code