Functions, not = to f(x)

--Originally published at PYTHON 3

Before creating and calling functions in Python 3, first we have to know what is a function in Python 3? So….

What is a function in Python 3?

A function is a code, (reusable code) that let us make a single related action. For example, the most common function I may think of is “print()” which is also an output, but Python let us create our very own functions/commands/methods.

So now we now what a function is, but now, how do we create a function?

To create a function first of all your are going to NEED the KEYWORD “def” (an abbreviation of the word define) which is indispensable to create a function, ’cause like the name says it you are going to define it, the next thing you need is the name of your function, so name it anyway you like, but I recommend its a name that reminds you what that function does or at at least is supposed to do lol. And at the end you add parentheses “()”, and inside this parentheses there should be the parameters/arguments of that function.

Here’s a more graphical example of how to create a function:

“def” + “nameofthefunction” + “(parameters/arguments)”

Screenshot from 2016-08-29 11-04-41

That is my creatingandcallingfunctions.py file and when I run it on the terminal it is suppose to print 14 lines of series of numbers.

Screenshot from 2016-08-29 11-08-25

and we are done?


Los XIX mandamientos de Python

--Originally published at PYTHON 3

1. Beautiful is better than ugly.

2. Explicit is better than implicit.

3. Simple is better than complex.

4. Complex is better than complicated.

5. Flat is better than nested.

6. Sparse is better than dense.

7. Readability counts.

8. Special cases aren't special enough to break the rules.

9. Although practicality beats purity.

10. Errors should never pass silently.

11. Unless explicitly silenced.

12. In the face of ambiguity, refuse the temptation to guess.

13.There should be one-- and preferably only one --obvious way to do it.

14. Although that way may not be obvious at first unless you're Dutch.

15. Now is better than never.

16. Although never is often better than *right* now.

17. The implementation is hard to explain, it's a bad idea.

18. If The implementation is easy to explain, it may be a good idea.

19. Namespaces are one honking great idea -- let's do more of those!

Basic types of Data

--Originally published at PYTHON 3

What are the basic types of data in Python 3?

There are five standard types of data in Python3:

Booleans: Tells us if something is true or false

 

Numbers: Like the name say this variable let us save numbers

Integers: Only whole numbers (1,2,3,87108)

Floats: Numbers with decimals (1.1, 1.4831,24384.0053)

Fractions: (½, 412/30)

Complex numbers: But it is really complex so I think I won’t be using that kind of data anyway soon.

 

Strings: which are sequences of Unicode characters, or in other words just plain text.

Lists: It is the most versatile datatype in Python, and like the name says it is a list of data, and this data doesn’t necessarily have to be of the same type.

list1 = [‘1′,’a’,’Jared’,’asxcverstefcbs’]

Tuples: A tuple is a list, that once it is created it cannot be modified.

tuple1 = (“a”,”adfgd”,”incambiable”)

Sets: A set is like an un-ordered bag of unique values.

set1 = {1,2,3,4,5}

Dictionaries: a dictionary is a way to store data just like a list, the difference is that you can use almost everything to search for the data, pretty much like a database which lets you store data and also organize it.

dict1 = [‘A’,’B’,’C’,’D’,’E’]

 


Input & If

--Originally published at COMPU 01

The next thing I learned at python was saving some information.

In the code I made, the idea was to ask the user for his/her name and type it in. Something like this…

name = input(“Enter your name: “)

After the user clicked Enter, a message would appear on the screen, so I did kind of the same work from my last code but I added the option of showing the name of the user by just adding a “+” and the name of my variable…

print(“Welcome ” +name)

Next thing, I made another input to ask the age of the user, almost like the first one, but this one instead needs to be an int and no a String ’cause we are saving a number, not a text.

age = int(input(“Enter your age: “))

Now the program will take this information and will decide to either show a message or not, by using an if and elif (else if) command.

if age >= 18:

     print(“Congratulations ” +name +” you are an adult”)

elif:

     print(“You are still fresh ” +name)

IT IS VERY IMPORTANT TO USE “TAB” IN ORDER TO GIVE THE INSTRUCTIONS!!!

 

Screenshot from 2016-08-16 20-06-29

Screenshot from 2016-08-16 20-07-34

 

 

 

 


Hallo Welt

--Originally published at COMPU 01

Hallo liebe Leute, diese ist meine erste Computercode.

Zuerst ich habe meine TextEditor app geöffnet, dann ich habe die klassische Worte “Hello World” geschrieben. aber ich habe das in Deutsch gemacht.

print(“Hallo Welt”)

 

Dannach ich habe meine Ubuntu terminal geöffnet mit der Schlüssel Kombination “ctrl+alt+t”.

 

Dann gehen wir nach meine Desktop mit der Code “cd” (das bedeutet “Change directory”) und “Desktop”.

 

Fantastisch!, Wir sind jetzt im Desktop, um alles die Unterlagen sehen, wir müssen “ls” schreiben (das bedeutet “list”).

 

und endlich, wir müssen “python3 + “nameoftextdocument.py” schreiben um unsere Computercode zu rennen. (Meine Dokumentname ist “hallo.py”).

 

 

 

Und dast ist alles, sehr einfach und toll:)