“While” Loops

--Originally published at Ricardo's Blog

I know this is probably too basic for this time of the semester, But it’s one of the posts I forgot to make during the semester. So here it goes.

A “while” loops its pretty basic, it’ll do whats inside of it WHILE some condition it’s happening. So if the condition of the loop is positivem the loop will keep running. Over and over and over and over again. Until the condition turns false.

while

So, in this example it’ll ask the user how much money does it have. While the user types a number lower than a 100 it;ll print what’s on the screen. If it says a number above 100 it’ll type both sentences.

 

So there ya’ go. Hope it helped you.

Thanks or reading.Byeeeeeeeeeeeeeeeeeeeeeeee.


Input and conditinal statements.

--Originally published at Ricardo's Blog

This is a different type of program, most of the other ones were just to program something, and sit back so we coukd watch what the program run on its own.

Here is a different type of program, one that you can “interact” with, or just type some stuff that the program is asking us to.

bmi

First, we put in the program to ask the user a name, with the “input” tag, then we ask the question, and print “Hello, (whatever the name of the user is)”.

Second, we ask the user its age with the “input” thing again, but since we are gonna use that value later to print something depending on the users age. We put the “int” command so that the computer will use the age data as a number, not a string.

Then we ask if they want to know their BMI, if they type “no”, the program will end. If they type “yes” doesn’t matter if it’s on caps or anything, it’ll ask the next question. Which is “What’s your weight in kilograms?” again, with the “int” command, because we’ll be using calculations later.

When we ask the next question, “What’s you height in meters?”, instead of using the “int” command (which is only used for whole numbers) we use the “float” command, which also involves all numbers in between the whole numbers.

At the end, we only use the variables from each question, and create the BMI formula in out code, then print it. That should be it.

This video really helped me a lot, I’ve been watching this YouTube channel since we started. And it has really helped me. I hope it helps y’all as well.

Thank you for watching. Hope you enjoyed.

Byeeeeeeee.


Open files using command prompt

--Originally published at Ricardo's Blog

First when you open your command prompt this will show, meaning that is your computer and telling you that is inside the C: folder, just like it shows my name. When you type “dir” it’ll show you a directory of the files or folder you have in there.

cmd 1

When you press enter, it’ll show a directory with all the folders that exist in that hard drive.

cmd-2

When you want to open  folder you must type “cd (folders name)”.                                   Example: >cd documents; then press enter. In my case I chose to open my music folder.cmd 3.JPG

Then I asked for the directory in that folder, showing me that I dont have any folders or files inside my Music folder. So I want to go back so I can choose another folder to look on. No problem, just type “cd..” with the 2  points, so when you press enter, it’ll take you back to the original folder.

cmd4

When I got back, I opened my videos folder, by typing “cd videos”, than I wanted to see what I had inside that folder so, again, I typed “dir” and showed me the two videos I have saved in my videos folder.

cmd5.JPG

To open one of those files you have to either type the name of the file or copy and paste it. But be careful, if the name of the file has spaces in it, you nee =d to put the name of the file inside quotation marks, as you can see here, and it should open without any problem.

cmd6.JPG

Finally, if it doesn’t have any spaces in the files name, you can just type it without quotation marks and it’ll open, just like that.

cmd7

This video

43787886.jpg
Continue reading "Open files using command prompt"

Functions that function

--Originally published at Ricardo's Blog

First of all, that title tho…

tim-and-eric-mind-blown.gif

Functions work as a big command but simplified. Like, if you want to draw things, instead of typing the loops iver and over again, you can just define a word or something, then make that function do the loops for you, and only type the word you setted up. Instead of doing what it’s show here, repeating commands.

functions1

In the example, if I don’t want to type the Loop to make a square everytime I want a square. I create a function that will make a square, by just typing “square”, it’ll do it.

functions0

Where it says “size” you can either type a number, so the square size will be a default with the value you specified, or type the word “size” inside the parenthesis, so when you enter the function you can choose the size of the square.

functions2

Then I made a ton of squares appear, with random colors, in random places and random sizes. For this, I made another loop, and in this loop I started by creating this sort of a workspace that only goes from -200 to 200 in the X scale, and from -200 to 20 on the Y scale. Then I told my turtle to lift the pen up, and asked it to move to a random place in X and a random place in Y, aske it to put the pen down and choose a random color to change to, using the color list that is above in the program. After that, Fred will change  its color and make a square, with a random size that is specified to go from either 10 or 200 pixels.

And I guess that is it about functions (And a little extra).

Thank you for reading.

Byeeeeee.


(Late) Zen of Python

--Originally published at Ricardo's Blog

I know this post is a little late, but, better late than never…

I was doing other Mastery topics, then I realized “I haven’t made one of the first things that are on the list”. So this is it, I’ll explain the 3 that caught my attention and explain why I think that is important.

 

Explicit is better than implicit:

I think this is a very important rule, because we know there’s people who can understand everything that is to understand, but there are people than can’t as well. So if you want to get something out there, it’s better for you to be sure every person can understan what your talking about, by being explicit. And not just expect people to read in between the lines.

 

Now is better than never:

Well, personally this is the one I liked the most. It’s better to get things done when you can, and procastinating is worse, because eventually things will add up and it’s very likely that you wont be able to handle it all, when it has been accumulating throughout time.

 

Readability counts:

Because not everyone is going to understand what you want to say just because, you need to make your something is well done so people can understand what you are talking about, so very important for people to understand what they’re reading.

 

Thank you for reading this late post.

Byeeee.


Saving and running programs

--Originally published at Ricardo's Blog

Usually you would use de Python IDLE to run small commands or try some new ones, but when you get more advanced in your work, with a ton of coding, I bet you’d like to save the progress you make day by day. To make a program that is a few commands longer than the usual.

So you can star a new file, so a new blank window will come out, works as a text editor, so you can copy, cut, paste and basically edit everything in your code, so you dont have to start over every single time.

save and run programs.PNG

So as you can see, I have my turtle window open, my Python shell, and the file I want to run. So I typed commands and loops and everything I could think of to make this blog post a little easy on the eyes. So the window that is open at the bottom right corner is the program in the editing box, so I can do whatever I want with this code, and when I want to run it, it’ll show the whole process in the Turtle window.

And I can see why this is usefull, becacuse people will want to save progress in their program.

I’ll be using this type of editing window more often to make my coding easier to save and to run it. This video helped me a lot to understand what this was, I actually really like this channel and I’d like to recommend it to y’all.

Thanks for reading.

Bye.

 


Fruity Loopies

--Originally published at Ricardo's Blog

Getting tired of typing the same commands over and over again?

Getting tired of not being able to do more stuff in less time because of those tedious commands?

Well, I’ve got a solution for you… It’s called Loops.

Loops can help you get rid of all those repeating commands that you type over and over again for numerous times a day. Whether you are drawing with turtles or just wan to get a simple table going, Loops has you covered.

Turtel loop.PNG

And as you can see in the example, it took you 10 commands to make a turtle draw a simple square. But, if you use Loops, as you can see in the last three lines, it only takes about THREE lines to get a square. Pretty cool, right?

VARIABLES LOOP.PNG

Alsoooooooooo, you can ask Python to make a sort of table, if you want. In this first example we wanted to print 3 columns that would count to 9 bit for each column, the result would be a little different. The first column will print the number from 1 to 9, the second column will square the value and then print the result, and finally the third column will cube the value and again print the result.

In the second example we setted 5 columns that will count from 1 to 7, the other columns will print the value times the number of the column that its on.

So I hope I was some great help for youuuuu. Thank you for reading and I hope oyu read my next post.

Bye


Variables and lists… Interesting

--Originally published at Ricardo's Blog

I was learning about Python watching a video in youtube, and found out variables were acutally a thing, later I found out most of the programing languages (if not all) have variables in them. So I could make a sum, a substraction, multiplication or division with this program. Also I can assign values to letters or full words and ask it to add two words that have values (Ex. “mom + dad”) and get an answer depending of the values said words had.

Variables.PNG

 

Also, in the same video the explained how to use lists of things we may need, for example numbers and items. The lists always start counting from zero, so the first item I type in a list, the computer will make it item number zero. Like it shows in the image below. And also change the value for each item without having to delete or reset the whole list.

Lists.PNG

 

Here’s the video that helped me understand how to use variables and lists.

hank you for reading this article.

Have a nice day!


Using Turtles in Python

--Originally published at Ricardo's Blog

So, a Turtle is a device that was invented to create drawings that were programed into a computer.

So I found this video that teaches me how to use them in Python, from making them appear, to change color, shape, thickness, draw lines, circles, arcs, make it turn, etc.

The video really explains step by step how to do it, and its really simple to understand.

Then I tried to use all of the cmmands the video taught me to form a word, and really, it only took me 5 minutes of repeating programming to finally get the result I wanted. Now I can try to do other stuff and learn more advanced commands to help me create more awesome stuff.

Turtle Python.PNG

Thank you for reding!