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"

While…

--Originally published at PYTHON 3

The whiles are useful when we need to make a loop in our code, by this I mean that after we are done with a set of instructions maybe we want to repeat the same instructions one more time, and another and another and another….., until a statement tells it to stop or even the user wants to make it stop.

The while differentiates from the for because we use when we don’t know how many times the code will execute, with the for we tell the program how many times to repeat the loop.

screenshot-from-2016-09-09-09-10-58

Here I am telling the program to generate a random number from 0 to 10, I am also creating an int variable x =1,

so if my random number is less or equal than 20, my random number will be added the x=1, and after that I am printing all the numbers till it gets equal to 20.

This is a while loop because I don’t know my initial number, maybe my initial random is 0 or 10, and one may need more loops to reach 20 than the another, that’s why I use a while, because I don’t know how many times to repeat the instructions until it reach the goal.

screenshot-from-2016-09-09-09-21-37

screenshot-from-2016-09-09-09-21-53

I learned while loops from here…? Check it out

http://www.python-course.eu/python3_loops.php

 

 


What if…? or elif…? or else?

--Originally published at PYTHON 3

The if help us to check conditions, and we usually use them with inputs.

 

For example…

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

I am making a variable called age which is an int/input.

 

if age >= 18:

(Instructions)

elif age < 18:  

        (Instructions)

else:

       (“Error, what are you typing?”)

 

After typing your age, the code is telling if that number is equal or greater than 18 it will run a set of instructions, any instructions the coder wants.

But if that condition doesn’t complete, we have our elif, which is our plan B (that will also run another set of instructions)

But if any of those statements aren’t true then we can use or else, which is like our plan C/ backup plan (which runs another set of instructions if all of the ones before aren’t true)

9ba2dc39-0aa4-40c5-bfbb-a84af7825364.gif

It’s that easy, yet so beautiful and amazing.

 

Here’s a python code I made using ifs, elifs, and else

Screenshot from 2016-09-05 21-59-02

Screenshot from 2016-09-05 21-59-31

Screenshot from 2016-09-05 21-58-00

I tried like 30 times and never got the right number, that’s bad luck.

Check out the page that helped me learn about ifs?

http://www.ibiblio.org/g2swap/byteofpython/read/if-statement.html

 

 


Import Modules

--Originally published at PYTHON 3

What is a module?

A module is an object that lets you organize your Python code.

A file consisting of python code, this can define functions classes and also variables, and it also can include runnable code.

Any python file “something.py” can be use as a module by executing the next code in another or brand new python file.

Import module1[, module2[, …..Module(n)]

In other words, a module lets us import directions/ functions / defined functions from another python file, and instead of writing the same commands on our new Python file, we just need to put our directions for example:

In the last blog I learned how to create and call functions, so in my file “creatingandcallingfunctions.py” I already have myinstruction /function“repeat()”

which prints a lot of lines with numbers, so in my new file “import.py” I just need to import.

Import creatingandcallingfuncitons

##It is very important that the files you are going to import are in the same directory as your new file, because that’s the way it works.

But the problem in this is that you may also import other modules which have a different function but with the same name, so you have to define from what file you are going to import that function

import creatingandcallingfuntions

creatingandcallingfunctions.repeat()

creatingandcallingfuncitons.repeat()

Screenshot from 2016-09-01 10-10-27

In my file “creatingandcallingfuntions.py” I already had instructions, which were printing 2 sets of numbers, and in this new file i[m importing this instructions and also giving the directions to import another 2 sets of numbers, so in total there should 4 sets of numbers.

Screenshot from 2016-09-01 10-11-53

 

Here is the link were I learned about modules:

http://www.tutorialspoint.com/python/python_modules.htm


Colors in Atom

--Originally published at PYTHON 3

I wanted to changed the colors/theme of my files in python, so I checked out a video in youtube which is very helpful.

  1. All you have to do is going to Edit/Preferences option:

Screenshot from 2016-08-30 20-56-22

 

2. Syntax Theme is where you can select all of your installed themes, but if you don’t like any of the pre-installed themes don’t worry, you can download themes created by different people for free, just go  to “install”, select “themes” and search what you want in the theme, for example, I searched the word “cool”, look for the ones you like the most and click on install.

Screenshot from 2016-08-30 20-57-10

 

3. I am a big fan of the video game series Fallout, so I installed a theme about this game

Screenshot from 2016-08-30 20-58-05

 

I went from this….

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

 

To this….

Screenshot from 2016-08-30 20-58-54

 

Screenshot from 2016-08-30 21-08-15

This looks really awesome but the only problem is that it is on color scheme, it isn’t very helpful or more easy to read as the other ones.

 

 

Here is the tutorial I followed for all this easy procedure?

 

 


Colors in Atom

--Originally published at PYTHON 3

I wanted to changed the colors/theme of my files in python, so I checked out a video in youtube which is very helpful.

  1. All you have to do is going to Edit/Preferences option:

Screenshot from 2016-08-30 20-56-22

 

2. Syntax Theme is where you can select all of your installed themes, but if you don’t like any of the pre-installed themes don’t worry, you can download themes created by different people for free, just go  to “install”, select “themes” and search what you want in the theme, for example, I searched the word “cool”, look for the ones you like the most and click on install.

Screenshot from 2016-08-30 20-57-10

 

3. I am a big fan of the video game series Fallout, so I installed a theme about this game

Screenshot from 2016-08-30 20-58-05

 

I went from this….

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

 

To this….

Screenshot from 2016-08-30 20-58-54

 

Screenshot from 2016-08-30 21-08-15

This looks really awesome but the only problem is that it is on color scheme, it isn’t very helpful or more easy to read as the other ones.

 

 

Here is the tutorial I followed for all this easy procedure?