Tuples :D

--Originally published at Just A Turtle Coding.

So we talked a little bit of lists and compared it to tuples, but what exactly is a tuple?

A tuple is basically a list that you cannot modify. If you create a tuple named grades and plugged in your grades of this partial, those grades will not be modifiable. 

How to create a tupple? You only need to put in the name and use () instead of [].

Example = (1,2,3,4,5)

That way, if you print Example(1), it will return 2
but you cannot modify it later in the program, that’s why programmers rarely use tuples, since they cannot be modified. 

Lists

--Originally published at Just A Turtle Coding.

What does a list means? Basically Python has a type of data that’s named list that’s closely related to a tuple. It is basically the same but we use [] instead of (). The only difference is that a list can be modifiable “on-the-go”. 

A list can be created by typing the name and adding some values, it will be indexed starting from 0

Let’s say that my friends are called Juan Pancho and Roberto

friends = [”Juan”,”Pancho”,”Roberto”]
then Juan would be 0, Pancho 1 and Roberto 2.
If I call to print friends[1], it would return Pancho.

I could also say that friends[1] = Paco, that would modify the value of Pancho and change it to Paco instead.

More info on: http://sthurlow.com/python/lesson06/

Deciding repetition

--Originally published at Just A Turtle Coding.

How to know which type of repetition to use… It’s a great question for programmers. 

One factor to take into account is the space you are allowed to use, how many bytes or megabytes or gigabytes are you allowed to use? 

Another factor to take into account is the length of the program and if you could make it shorter. A factorial can be made simpler if done with a repetition algorithm rather than using nested ifs or nested loops

One last factor to take into account is how simple it is for humans to read. If you just nest loops then it might be more complicated than if using a for loop.

Dictionaries

--Originally published at Just A Turtle Coding.

Yeah, you can have dictionaries in Python…
To create them it’s really easy, you type in the name and then start adding the elements. It is important that you type in the key:object since the key is what will define that value/string/object.

It is called dictionary because of the resemblance it has with a real dictionary where you read the word and its meaning. 

You can have as many dictionaries as you like, you only have to remember the name and the key; or you could just call the dictionary and it will print it. 

Remember that you can create dictionaries whenever you like. 

More info on this topic on: http://christa-vanilla98.blogspot.mx/ 

Tuples :D

--Originally published at Just A Turtle Coding.

So we talked a little bit of lists and compared it to tuples, but what exactly is a tuple?

A tuple is basically a list that you cannot modify. If you create a tuple named grades and plugged in your grades of this partial, those grades will not be modifiable. 

How to create a tupple? You only need to put in the name and use () instead of [].

Example = (1,2,3,4,5)

That way, if you print Example(1), it will return 2
but you cannot modify it later in the program, that’s why programmers rarely use tuples, since they cannot be modified. 

Lists

--Originally published at Just A Turtle Coding.

What does a list means? Basically Python has a type of data that’s named list that’s closely related to a tuple. It is basically the same but we use [] instead of (). The only difference is that a list can be modifiable “on-the-go”. 

A list can be created by typing the name and adding some values, it will be indexed starting from 0

Let’s say that my friends are called Juan Pancho and Roberto

friends = [”Juan”,”Pancho”,”Roberto”]
then Juan would be 0, Pancho 1 and Roberto 2.
If I call to print friends[1], it would return Pancho.

I could also say that friends[1] = Paco, that would modify the value of Pancho and change it to Paco instead.

More info on: http://sthurlow.com/python/lesson06/

Validating entries :D

--Originally published at Just A Turtle Coding.

When validating user entries, you have to know what you’re looking for. When a function uses a specific type of variables, it might crash if the user inputs something that the function can’t use. To apply this, you can call a try function.

For more info, you can consult: http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response 

while True:
    try:
        # Note: Python 2.x users should use raw_input, the equivalent of 3.x's input
        age = int(input("Please enter your age: "))
    except ValueError:
        print("Sorry, I didn't understand that.")
        #better try again... Return to the start of the loop
        continue
    else:
        #age was successfully parsed!
        #we're ready to exit the loop.
        break
if age >= 18: 
    print("You are able to vote in the United States!")
else:
    print("You are not able to vote in the United States.")

Deciding repetition

--Originally published at Just A Turtle Coding.

How to know which type of repetition to use… It’s a great question for programmers. 

One factor to take into account is the space you are allowed to use, how many bytes or megabytes or gigabytes are you allowed to use? 

Another factor to take into account is the length of the program and if you could make it shorter. A factorial can be made simpler if done with a repetition algorithm rather than using nested ifs or nested loops

One last factor to take into account is how simple it is for humans to read. If you just nest loops then it might be more complicated than if using a for loop.

Dictionaries

--Originally published at Just A Turtle Coding.

Yeah, you can have dictionaries in Python…
To create them it’s really easy, you type in the name and then start adding the elements. It is important that you type in the key:object since the key is what will define that value/string/object.

It is called dictionary because of the resemblance it has with a real dictionary where you read the word and its meaning. 

You can have as many dictionaries as you like, you only have to remember the name and the key; or you could just call the dictionary and it will print it. 

Remember that you can create dictionaries whenever you like. 

More info on this topic on: http://christa-vanilla98.blogspot.mx/