#TC101

--Originally published at Coding with jared

Siento que es raro decirle semestre a este largo viaje que recorrimos cuando en realidad solo duro 3 meses y medio, he aprendido bastante desde principios de agosto sobre programación, suelo entender todos los conceptos y funciones de comandos, pero lo que me falta desarrollar es la creatividad al momento de escribir un código y es por eso que aprecio a las personas que se dedican a programar, son demasiado ingeniosas y les sobra imaginación. Con #TC101 vi lo básico de Python3, gracias a esto también aprendí a usar de una mejor manera Ubuntu, ya que tuve que instalar varios programas para poder realizar todos los códigos. Con Ken aprendí que no necesitamos de alguién enfrente de nosotros tratandonos de enseñar algo, sino debemos de tratar de enseñarnos a nosotros mismos por mera voluntad propia.


Writing

--Originally published at Coding with jared

There´s another way to write down notes without using Word, LibreOffice, Notepad or any other famous text editors…..

Resultado de imagen para libreoffice writer

Resultado de imagen para wordResultado de imagen para no more

You can now create your very own text files with Python3, and it is pretty easy, you may only need a command o do it which is .write(“Whatever You Want”)

You may also wanto to create a .txt file, so in order to do this we need to make a variable

You need the command open(), and inside the parentheses you can name your file, but it has to end with .txt, then you use a comma , parentheses and “w”, the w means that you are able to write on that file.

screenshot-from-2016-11-23-19-58-21

You may run this code on the terminal , but the terminal won´t show anything, but the file will be created, here appears mine on my desktop.

screenshot-from-2016-11-23-20-02-21

 

Now to write on the new file you need to write the name of the variable plus .write(), and inside the parentheses between brackets you write whaterver you want.

screenshot-from-2016-11-23-20-03-17

Be sure to save the file and run it again on the terminal, once again it will show nothing on it…

screenshot-from-2016-11-23-20-04-03

 

but if you double click your .txt file. the text you wrote on python will appear on the text editor.

screenshot-from-2016-11-23-20-04-47

?

I learned to create and modify text files from this video:

 

Cheers to Computer Science UK for making great videos.

 

 


Reading

--Originally published at Coding with jared

Just learned how to open .txt files on the terminal using python 3, it is very easy to use, you will feel like a hacker just to open a file for reading it.

the comand we need is open(“filename.txt”)

VERY IMPORTANT!

The .txt files and the .py file must be in the same directory in order to proceed.

Screenshot from 2016-11-20 20-13-25.png

My .py and .txt files are in my Desktop, you cans see that I got two books, the Bible and a book of Harry Potter, now let´s move on to the code

Screenshot from 2016-11-20 20-14-45.png

Here I am making a menu of the books available, and also I am asking the user to enter not the number, but the name of the book. if the name of the book is equal to Harry Potter or The Bible, the code will continue, we must name a variable, I called it “text” equal to open(“nameofbook.txt”).

After that wee need to print the file in the terminal so we write this, print (text.read()).

Here is how it works on the terminal…

Screenshot from 2016-11-20 20-15-15.png

Screenshot from 2016-11-20 20-15-31.png

Now I can read Harry Potter and the chamber of secrets on my ubuntu terminal..

Watch where i learned about opening filess.


You can´t do that

--Originally published at Coding with jared

Today´s blog is about validation of the user input, before starting with this topic, we need to know what is data validation.

data validation: Making sure that a program operates based on clean, correct and useful data.

data validation in programming is needed to continue procedures, for example if a program is asking for an integer, and a the user gives a string as answer the program, may crashed or send an error message that the answer given is nott a correct option in order to continue the program.

The errors are handled with try and except.

Try works as the follow

try: ´´´ Instructions …´´´

except : ´´´Ínstructins…´´´

first all the instructions from try to except are executed, but if no exception is find that block ends and now we continue to the block except.

For example, in this program of my calculator in Spanish, i am giving the user the option to select an what operations he/she wants to do, but there are only four options, numbered from 1 to 4, and to select it you just have to select the number and press enter, but what if the user is a smart ass and instead of give as answer the given options he/she decides to enter another number…

Screenshot from 2016-11-20 19-06-11.png

know i am able, to outsmart the smartass

 

Screenshot from 2016-11-20 19-12-21.png

 

This is where I learned about validations, try and except statements :9

https://docs.python.org/3/tutorial/errors.html


[],(),{}

--Originally published at Coding with jared

What are lists, tuples and dictionaries in Python 3?

Lists:

Like we already know a list in python is a list of values, each value is numbered starting from 0, it is possible to modify these lists by adding or removing informaiton.

You use this []

Students = [“juan”,”pedro”,michael”,”jackson”]

 

Tuples:

Pretty similar to lists, the only difference is that you can’t add or remove values form it.

You use this ()

meses = (‘Enero’,’Febrero’,’Marzo’,’Abril’,’Mayo’,’Junio’,’Julio’,’Agosto’,’Septiembre’,’Octubre’,’Noviembre’,’Diciembre’)

 

Dictionaries:

A dictionary is also like a list but the difference is that you make variables and you give them a value or a definition.

Name = key

definition = value

The keys and values that are put respectively aren’t numbered, you also can add, remove and even modify the values and keys from it.

You use this {}

oxxo = {‘gansito’:8,’sabritas’:10,’agua’:9}

 

I learned all this on this page, check it out: http://sthurlow.com/python/lesson06/

 


Sentence Encryption Challenge

--Originally published at PYTHON 3

A project my comrade Luis Palomino and I made on Thursday

Check out Palomino’s blog for some good python challenges:

https://luispalominotblog.wordpress.com/

and follow us on GitHub

 

This is a code to encrypt a sentence given by the user, it is already made, but the question is, can you tell us how each of the functions work to make a secret word?

Screenshot from 2016-10-15 20-09-08.png

Screenshot from 2016-10-15 20-14-54.png

?


Mixing It Up

--Originally published at PYTHON 3

In this code we are going to learn how to turn a string object into a list and also how to make a total new sentence by mixing up in a random order all the characters in it.

First we need to import the random library, then the sentence we want to mix up, it may be an input but in this program I’ve wrote already a sentence.

sentence = “one two three four five six seven, all good children go to heaven”

to make this sentence into a list we do the next

sentence_list = list(sentence)

and like the program before we need a en empty string object

mix = “”

next we do a for,

for each letter in our range of the list from 0 to the length of list, our empty string named mix will be added a random character from the list.

and to end these we just print it, here is the final result.

screenshot-from-2016-10-15-19-43-11

screenshot-from-2016-10-15-19-43-41

?


Without Vowels

--Originally published at PYTHON 3

This mini program consists of converting any sentence the user gives in the same sentence but without vowels. For example, making the famous sentence:

The quick brown fox jumped over the lazy dog

The qck brwn fx jmpd vr th lzy dg

7a5a8f10364877.560e3a9483d9b.png

to do this we need a list with our vowels

vowels = (“a”,”e”,”i”,”o”,”u”)

and an empty string object that’s gonna show our final sentence without the vowels.

final = “”

Now here is the tricky part…

we are going to use a for loop, that is going to check all the letters in the sentence we are going to write, and if that sentence is not a vowel it will save in our variable final. and at the end we just print(final)

screenshot-from-2016-10-15-19-23-40

screenshot-from-2016-10-15-19-05-34


Dice

--Originally published at PYTHON 3

A month without posting any new blogs because of different reasons i’m back with some mini projects I’ve been developing since the beginning of the partial, this is the first one which is a program that rolls a dice, a very simple code.

To do this program we need to import the random library, next we do our object “dice” as a list that includes the 6 numbers

dice = [1,2,3,4,5,6]

we print a welcome text and make an input to press enter and start a while loop, and while the loop is true it will run the next code:

while True:

pass #it will run the instructions in order

print(“The number is: ” , random.choice(dice)) #random.choice() selects a random object from a list
print(‘\n’)
print(“Want to roll again?”+’\n’)
print(“(1) Yes.”+’\n’)
print(“(2) No.”+’\n’)

Now the program has given a number from 1 to 6 and is asking us if we want to run it again

answer = int(input(‘\n’))

if answer == 2:
break

elif answer != 1:
print(“Sorry but that’s not an option… Try again”+’\n’)

screenshot-from-2016-10-15-17-09-14

screenshot-from-2016-10-15-17-08-38

Now i can play monopoly with my own virtual dice

monopoly


Taschenrechner

--Originally published at PYTHON 3

A time ago I made a little project, which is kind of a pocket calculator. A program that lets you make additions, subtractions, divisions and multiplications. Let’s see how that works…

I wanted a nice menu, a nice welcome to my program, for that I made some prints at the beginning to, and immediately the menu options.

Each option has a number (1,2,3,4)

(1) Addition

(2) Subtraction

(3) Multiplication

(4) Division

And to select an option I made an input variable, now the user gets the option to choose whatever operation he wants, this is the part we go to the ifs, my first if is if the variable is equal to the option 1 (Addition), so if the user had select the number one the instructions on the if will run which is a print with instructions for the user, two input variables for the numbers to add and at the end a print to show the result. All this procedure is the same with the other options in the calculator, but now instead of using if we a re using elif, but if the user is a smart ass and declares a number which is neither of the input options there is an else which will print that there has been an error and will ask the user to try it again.

After the math operation its done and the result has been shown on the terminal, my program will ask the user if he wants to make another operation, for that I made another print menu.

print(“Want to make another operation?”)

print(“(1) Yes”)

print(“(2) No”)

 

If the user wants to make another operation then we need to run all of our code again, that’s why I used a while at the beginning of

selection_003
selection_004
selection_005
selection_007
?
Continue reading "Taschenrechner"