Tag Archives: mastery27

Mastery 27

Here is my completed code for mastery 27 of Kens TC1017 C++ course: mastery27

here is a picture of the running code:

1017 27

Mastery 27

En la siguiente imagen utilice el programa del proyecto final para mostrar algunas fuciones bool.

El tipo bool está especialmente adaptado a para realizar comprobaciones lógicas; de hecho, todo el álgebra de Boole se basa justamente en el uso de este tipo de variables de solo dos valores mutuamente excluyentes.

Por su parte, las palabras clave false y true son literales que tienen valores predefinidos (podemos considerar que son objetos de tipo booleano de valor constante predefinido). false tiene el valor falso (numéricamente es cero), true tiene el valor cierto (numéricamente es uno). 

 

#Mastery27 #TC1017

 

Validated user input in C++

Practicamente todo el tiempo es necesario validar si la respuesta del usuario es válida, ya que muchas veces el programa pide numero o letras y responder algo diferente a esto puede ocasionar que el programa “se rompa” les dejo un tutorial hecho por mi para aprender a cómo utilizar estas herramientas fundamentales: 

YOUTUBE:

http://youtu.be/7pTmBh0ZiO0?hd=1

#mastery27 https://www.youtube.com/watch?v=H-JTBqxM2Mo

Mastery 27

Hello people:

For mastery 27 I created a program that asks the user for different numbers and it checks that the user is actually introducing what the program is asking to. Take a look at the code:

 

In this program the user is asked to introduce and integer number, and if she/he introduce for example a number with decimals, the program does not accept the input and it keeps asking for an integer until the user introduces the correct number.

In the second part, the user is asked to introduce a number between an specific range, and the same thing hapens if the user introduces a number out if the range. 

Validating user input might be a bit complicated because the user can introduce whatever she/he wants, and sometimes an incorrect input might cause a program to explote.

 

Validated user input in C++


Validated user input in C++

Validated user input in C++

As a programer sometimes it is necessary, to validate a user entry into a program, there is a ver easy way to do that using if and else, you can also do it with do and while, but my example consists of the first, so I’m going to explain that one.
As you can see I used a string as the correct user name, if the username is not the same as the one I the I gave to the string, it will show “Usuario incorrecto”, that’s how validation works, I hope this was helpful.

M27 – Validated user input in C++

Hey everybody!

In this time I will show you how to validate user input and why you should do it in your codes. I hope you enjoy it!

https://www.dropbox.com/s/8yhuguda0ljpek4/M27%20Validation.mp4?dl=0

Uso de diccionarios #Mastery27 #Tc1014

this is the link for my video:

Uso de diccionarios #Mastery27 #Tc1014

Creating and Using Dictionaries in Python

Another one of the Python types are dictionaries. They are bascially an unordered list of key-value related elements, this means that you have an element in the key group and you assign an arbitrary object as its definition. 

They work much like language dictionaries, where for each word, or key, you have a definition for that word, or the value; so whenever you ask for a certain key, you get its corresponding value in return. 

Dictionaries can be modified by adding values or by redefining the value for a given key. Lets see this whith examples.

>>>dict={}

Dictionaries are created using {}, and you have to define key : value pairs, separated by a coma.

>>>dict{"Name":"Manuel","Career":"IMT"}

>>>dict 

{‘Name’: ‘Manuel’, ‘Career’: ‘IMT’}

 

To add a new pair to the dictionary you just declare it, using the key as the index and the value 

>>>dict["UNI"]="ITESM"

>>>dict

{‘UNI’: ‘ITESM’, ‘Name’: ‘Manuel’, ‘Career’: ‘IMT’}

 

When you type a value that has the same key, the old value is overwritten so you can only have one value for any key.

>>>dict["Name"]="Ken"

{‘UNI’: ‘ITESM’, ‘Name’: ‘Ken’, ‘Career’: ‘IMT’}

 

If you want to implement Dictionaries in a boolean context, whenever a dicotionary has at least one element, it will return True, if it doesn’t have any element it returns False.

I used this pages as reference for this post please check them:

Python Variables Types

Native Datatypes

 

 

This is my of my

Mastery 27. Creation and use of Dictionaries

Dictionaries are another helpful data built into python.

Unlike other data types which are indexed by range of numbers, dictionaries are indexed by keys, which can be any immutable value, such as strings, numbers or even tuples (Lists wouln’d work for keys because they can always be changed).

The syntax for a dictionary is the following:

>>Dict={‘key1’=value1, ‘key2’=value2, ‘key3’=value3}

If we wanted to add a new value into the dictionary, we have to add it by entering a new key, for example:

>>Dict[‘key4’]= value4

And we would assume that this new value is added to the end of the dictionary, but unfortunately this wont happen, but it doesnt matter, because even if this new value is stored randomly into the dictionary we can always find it by his key.

For example, if we want to print value3, we type the following:

>>print (Dict[‘key3’])

and as ‘key3’ is the key for value3, value3 will get printed.

In the same way we can modify the value of a key and we can even add as many values we want for only one key by adding a list as the value of the refered key. For example, if we wanted to modify the value of ‘key1’ for a list containing 3 values, the syntax would be the following:

>>Dict[‘key1’]=[val0,val1,val2]

And if we wanted to acces specifically to the second value of a given key (key1, for example), the syntax would be the following:

>>print (Dict[‘key1’][1])

Also we can add a dictionary as the value of the key of a main dictionary, it is just matter of the needs of your program.

If you want to learn more about dictionaries, you can go to this link: https://docs.python.org/2/tutorial/datastructures.html