Author Archives: Ismael Lizárraga

Validated user input in Python. Mastery 29.

If you’re expecting an specific in Python, you can validate the input of the user  by comparing that input to the input you expect.

Example:

 

This program calculates the factorial.

At the end, it asks the user to input if he wants to try another. If the user types y, then, the program executes again. If n or different than y, the program ends. That’s the reason why the main program executes after the while (x==”y”) condition.

Cars. WSQ16.

My WSQ16 is done.

Take a look at my code.

For getting this mastery done you should take into consideration everything we have seen so far in the assignments for class, also, read about how to handle files with Python. It will be VERY HELPFUL!

https://github.com/IsmaLga/Masteries-WSQs/blob/master/wsq16.py

#WSQ16

User Input (text based) in Python (basic). Mastery 28.

Programs in Python are able to receive input coming from the user. The function able to do this is the input function. When this function is called, the program stops and waits for the user to type something. The program continues when the user press return or enter.

Example:

After input(), the Python shell received the text that I wrote and that piece of text was assigned to the variable text, so when I print the text variable I am able to read the same text that I typed.

Also, you can prompt to the user what to input, per example:

If you want to see the input in a new line, use the sequence n at the end of the prompt. Example:

Can you see the difference? In my opinion it looks nicer.

If you expect the user to type a certain type, you can indicate that in your code. Example:

But if I type something different than an integer I get an error message:

So, this is basically how you handle basic input from the user.

28

 

 

 

 

 

Creation and Use of Strings in Python. Mastery 26.

A string is a sequence of characters. You can access the characters one at a time with the bracket operator.

Per example, let’s declare a string variable called car containing a sequence of characters forming the word mazda6.

In this example I’m calling the character corresponding to the third value of index of characters. Remember that the index starts at 0, so the character 0 will be c, the character 1 a, the character 2 z and so on.

Len.

The function len is able to return the numbers of characters contained in a string. Example:

 

If you want to get the last character of a string you can try something like this:

Traversal.

The process of dealing one string character at time and doing something to it, is called traversal processing.

Example:

This prints individually each of the characters contained inside the car string.

Slices.

Slices are segment of strings. Selecting slices of a certain strings is really easy.

Example:

The slice that I’m calling in this example is one going from the index 0 to the 4th index. Notice that using the 5 in the brackets means calling the previous character in the index. So the bracket works something like this [firstindex:lastindex+1].

Because…

Immutability.

Strings are immutable, that meaning that you are not able to change an existing string. The best thing you can do to deal with this is creating a new string that is a variation from the original.

Example, let’s call a new model ‘mazda3’:

You can appreciate that I’m calling the slice that contains the word ‘mazda’ and I’m adding a ‘3’ to the end, so I have a new string called new model containing the string ‘Mazda3’

Counting.

Also, you can go a little forward and count the times that a character appears in a string. Let’s count how many times the ‘a’ appears in ‘Mazda6’.

 

These are somes of the things that you can do with a string. Have fun 😀

 

 

26

Being successful at #TC1014? You should read this!

My advice for future students of this class!

 

https://www.youtube.com/watch?v=ioUyOXNE444

Quiz 11. Apr 27th.

Heres the code for of

Question 1: https://github.com/IsmaLga/Quiz11/blob/master/Q1.py

Question 2: https://github.com/IsmaLga/Quiz11/blob/master/Q2.py

 

I really recomend understanding of how to work with files in Python. This helped a lot in the process of writing the code for these two masteries.

Quiz10. 23/Apr

Heres the code for of

Question 1: https://github.com/IsmaLga/Quiz10/blob/master/q1.py

Question 2: https://github.com/IsmaLga/Quiz10/blob/master/q2.py

 

I don’t remember at which point at this course we mad a similar program to question 1 for the course.

Question 2 I made it with help of a friend.

Use of for loops is required, and also understanding of lists.

 

 

The semester is ending when it’s time for #ECOS !

Hello everyone, it’s time for ECOS in ITESM GDA, one way for directors and professors to get feedback from students.

I encourage everyone at Tec to do the ECOS as soon as possible.

Here’s mine! You can do your own at www.mitec.itesm.mx

 

 

#ECOS #TC1014

Final Dash. WSQ15.

My plan from here to the end of the course is the following:

 

Before April 23: By this day all WSQs and Masteries assigned that week should be done.

Before April 30: By this day all WSQs and Masteries assigned that week should be done. Plus, I’ll start reviewing my masteries and start working on the ones left.

Before May 6: All WSQs, Masteries and Quizzes should already be up for that day.

Before exam: I will be a master of TC1014.

Quiz9. 16/Abr

Hi, this post is for quiz9, the assignment is reviewing our examen and get our code right.

 

In the programs for this quiz conditional statements, for loops and while loops are used.

Take a look at the code in the following links:

 

Repository: https://github.com/IsmaLga/quiz9/tree/master

q1 fibonacci: https://github.com/IsmaLga/quiz9/blob/master/q1.py

q2 superpower: https://github.com/IsmaLga/quiz9/blob/master/q2.py

q3 triangulo: https://github.com/IsmaLga/quiz9/blob/master/q3.py

q4 distancia: https://github.com/IsmaLga/quiz9/blob/master/q4.py