Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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.
Continue reading ]]>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.
]]>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
]]>
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
If you want to see the input in a new line, use the sequence n at the end of the prompt. Example:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;} Can you see the difference? In my opinion it looks nicer.
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
If you expect the user to type a certain type, you can indicate that in your code. Example:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
But if I type something different than an integer I get an error message:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
So, this is basically how you handle basic input from the user.
#Mastery28
Continue reading ]]>
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.
#Mastery28
]]>
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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.
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
If you want to get the last character of a string you can try something like this:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
Traversal.
The process of dealing one string character at time and doing something to it, is called traversal processing.
Example:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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…
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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’:
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
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’.
Normal 0 21 false false false ES-MX X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabla normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0cm; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}
These are somes of the things that you can do with a string. Have fun :D
#Mastery26
Continue reading ]]>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
#Mastery26
]]>My advice for future students of this class!
]]>
Heres the code for #QUIZ11 of #TC1014
Question 1: https:/
Question 2: https:/
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.
]]>Heres the code for #QUIZ10 of #TC1014
Question 1: https:/
Question 2: https:/
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.
]]>
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
Continue reading ]]>
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
]]>
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.
]]>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:/
q1 fibonacci: https:/
q2 superpower: https:/
q3 triangulo: https:/
q4 distancia: https:/
]]>