Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/feed-rss2.php on line 8
‘#mastery29’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Thu, 26 Nov 2015 05:42:38 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Mastery28 & Mastery29 https://kenscourses.com/tc101fall2015/2015/mastery28-mastery29-2/ Thu, 26 Nov 2015 05:42:38 +0000 http://finntec.wordpress.com/?p=98 Those are the masteries about

  • User input (text based) in Python (basic)
  • Validated user input in Python

 

You can find my video here:

]]>
https://creativecommons.org/licenses/by/4.0/
mastery 28 and 29 https://kenscourses.com/tc101fall2015/2015/mastery-28-and-29/ Thu, 26 Nov 2015 04:06:58 +0000 http://ilkapython.wordpress.com/?p=172

]]>
https://creativecommons.org/licenses/by/4.0/
#Mastery29 https://kenscourses.com/tc101fall2015/2015/mastery29-3/ Thu, 26 Nov 2015 02:39:59 +0000 http://jsphsalazar.wordpress.com/?p=149 ]]> You can do a lot of things with Python, one of them is validate the input of the user. Basically, you can compare the input from the user and the input you expect.

Here’s an example:

29

As you can see, at the end of the program it asks to the user if he/she want to try with another number or ends.

Nice, right?

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery28 & Mastery29 https://kenscourses.com/tc101fall2015/2015/mastery28-mastery29/ Thu, 26 Nov 2015 01:22:16 +0000 http://5nbppkkyj.wordpress.com/?p=195 ]]> User input (text based) in Python (basic) and Validated user input in Python

One way to have data in your code is to get it from external sources such as databases, another computer, the Internet, etc. The options are endless(sort of). Depending on what your code is about you will find that user input is quite valuable if you know what to do with it, we shall see more about this later on. First, we need to see how to get it.

Python makes this super easy for you because it has a built-in function which is unsurprisingly called input.

To declare an input you just add a parenthesis and type your prompt. In the example below I ask for someone’s age or you can get more complex data by creating lists or dictionaries with the input.

n = input(“Please enter your age: “)

The computer kind of replaces “Please enter your name:” with whatever the user writes, which is a prompt string. And when the function is evaluated the input is shown. Remember that whatever the user types, even if it is a number or a character, will ultimately be a string. If you want to use it in any other way then you would use other functions such float or int to modify it.

So in the code above, the variable n is replaced by whatever the user inputs, according to my example if I were to use my short program n will become my age as a string. The next piece of code shows you how to convert it into an integer using the int function.

n = input(“Please enter your age: “)

age = int(n)

I simply created a new variable called age and the value of my variable is mainly the user input but the function int before the name of the variable changes my age as a string intomy age as an integer. Allowing me to work with it.

So what happens if the user input does not match what you’re asking for? You validate it using =.

n = input(“Please enter your age: “)

if n == int:

print(“You look younger!”)

else:

print(“Not a number!”)

Conditionals are useful for this. My code above validates their input by asking whether n is an integer if it is not it prints “not a number” and if it is an integer it prints a very fake compliment.

]]>
https://creativecommons.org/licenses/by/4.0/
Input (user input) / Validate Input https://kenscourses.com/tc101fall2015/2015/input-user-input-validate-input/ Thu, 26 Nov 2015 00:09:00 +0000 http://asimplemaniseepythonipresslike.wordpress.com/?p=360 ]]> Sometimes we need the feedback from the user and this is how we made by input(), if you don’t know how this is done please check the video below 😀 and learn how to validate what the users typed!!!

Here’s the video:

]]>
https://creativecommons.org/licenses/by/4.0/
Masteries 29,9: Validate what the user inputs https://kenscourses.com/tc101fall2015/2015/masteries-299-validate-what-the-user-inputs/ Wed, 25 Nov 2015 15:43:59 +0000 http://charliegdrummer.wordpress.com/?p=240 Continúa leyendo Masteries 29,9: Validate what the user inputs]]> Here I will show show an easy way to validate what the user inputs specially what type of data is typing.

That means that you can restrict the user to type something no longer than 10 characters, or to type only an integer or a float. Here I going to show you those three cases (something no longer than ten characters, an integer, and a float).

 

So let’s start with the easiest one; to restrict the number of character the user can type, it is easy to use the length command.

len(variable)

it will return the number of characters in case of a string, the number of elements it has in case of a list.

REMEMBER, in order to do this, the variablke must be either a string or a list, otherwise it won’t work

With a loop with the condition of what the user is typing is longer than ten characters, you can r4estrict the interaction of the user and don’t let him go until he types what you want

So for the program we will ask a nickname no longer than ten characters, the loop after asking the nickname will be:

string

So it will loop untill the user types it correctly

 

Then, we will review a little harder one; to restrict the user to only type an integer; that means the input won’t have a “.” inside of it, and it can be converted to integer via python.

There exists a common way to validate that which is by exceptions in a loop. With a loop that it’s only condition is to be true, you will use the command try, to, well, try to do something, in this case, to convert the input of the user to integer via python, variable = int(variable); if it results like an error, represented in python as ValueError, then it will ask again for the number. This loop is to make sure the user didn’t input letters, just numbers.

After doing that, is necessary to verify if the input has a decimal point”.”, in that case, it will ask again for the number

So it will look like this

integer

 

The last one, the float, its a little more ease, it just have to work if you try to convert it to float; you will use the same structure, but you will try to convert it to float instead to int variable = float(variable)

It will result like this:

float

Here you saw not just how to validate, but learned the basic types of data

The strings, that are just characters

The integers, that are just numbers, not fractions, not decimals

The floats, that are numbers with decimal points

 

It is easy isn’t it?

Eazy-E.jpg

]]>
https://creativecommons.org/licenses/by/4.0/
MASTERY29 https://kenscourses.com/tc101fall2015/2015/mastery29-2/ Mon, 23 Nov 2015 02:29:10 +0000 http://luiscortestec.wordpress.com/?p=150

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery 29 – Validated input https://kenscourses.com/tc101fall2015/2015/mastery29-validated-input/ Sat, 24 Oct 2015 21:59:00 +0000 http://kenscourses.com/tc101fall2015/?guid=e567e38d1b4bdee4a90e58eab651d256 I had some trouble figuring out how use a condition with the input type but i solved it with some reading. Here is the code that prove it:

The program will only start to work if it is a positive integer number, otherwise (if it is a string or a negative number) it will ask the user for the number repetitive times until the program receives a positive integer number

]]>
https://creativecommons.org/licenses/by/4.0/
#Mastery29 https://kenscourses.com/tc101fall2015/2015/mastery29/ Wed, 16 Sep 2015 01:01:22 +0000 http://pololarinette.wordpress.com/?p=67 Hey today we are going to learn how to :

  1. Validated user input in Python

#Mastery29 :

Have a good day !

]]>
https://creativecommons.org/licenses/by/4.0/