#100DaysOfCoding – Day 05 – Challenge 05 of 05

The exercise in today’s challenge is to create a Python code to generate a random password from letters, numbers and symbols.

Let’s start by specifying the letters, numbers and symbols that are mostly accepted by any website when creating passwords.

Then some print statements asking the user for their input in terms of how many characters of each kind they want to use for their password.

Then we need to import the random module which we need to create some random arrangements by saying:

Then I created 3 “for loops” for my letters, symbols and numbers.

Then I combined them all into a single password in the form of letters+symbols+numbers.

and that completes the easy part of this challenge. The next higher level for this challenge is to randomise these characters to make it difficult to hack by any professional hackers.

I haven’t seen the solution from our instructor but after googling, I found out that I can use the function called random.shuffle(). This function doesn’t work with string. It can’t accept a string argument.

The first thing we need to do is to convert the random_password from line 42 to a list. Let’s do that by saying: new_list = list(random_password)

Next, let’s reshuffle it by saying random.shuffle(new_list). I did mine twice here.

Then let’s view the result using the print statement by saying print(new_list).

Finally, time to join back those characters in a list using the join() function

Then let’s view the final result using the print statement by saying print(final_password).

Next, we are ready to run the code.

Here is the sample result of selecting 8 letters, 3 numbers and 5 symbols for the password:

Click the link below to watch this in action:

Until then. Have a great day.

Cheers.

#100DaysOfCoding – Day 05 – Challenge 04 of 05

The challenge for today is inspired by a game called “FizzBuzz” game where from a given range of numbers, in this case from 1 to 100, we will write a program to satisfy these 3 conditions.

  1. When the number is divisible by 3 then instead of printing the number it should print “Fizz”.
  2. When the number is divisible by 5, then instead of printing the number it should print “Buzz”.
  3. And finally, if the number is divisible by both 3 and 5 e.g. 15 then instead of the number it should print “FizzBuzz”

e.g. it might start off like this:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
....etc

Hint

  1. Remember your answer should start from 1 and go up to and including 100.
  2. Each number/text should be printed on a separate line.

My Solution

Let’s start by creating a range of numbers from 1 to 100, inclusive.

Next, if you start by creating an if statement to capture any numbers divisible by 3 or 5, for instance, 15, whoever comes first will be processed first. So if you say:

From here the number 15 will be replaced by Fizz which is something that we don’t want for any number that is divisible by 3 and 5.

The best way to capture or processed first any number that is divisible by 3 and 5 is to put them on top before looking at any number that is specifically divisible only to 3 OR 5.

So here is the completed Python code:

And here is the partial result:

Until then! Have a great day.

Cheers.

#100DaysOfCoding – Day 05 – Challenge 03 of 05

Instructions

You are going to write a program that calculates the sum of all the even numbers from 1 to 100. Thus, the first even number would be 2 and the last one is 100:

i.e. 2 + 4 + 6 + 8 +10 … + 98 + 100

Important, there should only be 1 print statement in your console output. It should just print the final total and not every step of the calculation.

Hint

  1. There are quite a few ways of solving this problem, but you will need to use the range() function in any of the solutions.

And here is my solution:

And here is the result when you run this code:

Positive SSL