#100DaysOfCoding – Day 04 – Challenge 03

In this challenge, our job is to write a program that allows us to mark a square on the map using a two-digit system. The first digit is the vertical column number and the second digit is the horizontal row number.

Here is an example with user input = 23

I am sure that different Python programmers have different ways of solving this challenge. For me, after 20 minutes of thinking about how to solve the challenge, I came up with this first solution using the “if function”.

My first solution

If I have a huge number of lists, I believe using the “if function” is not the best solution, so I have to think of a way to replace the corresponding column and row according to the user input. The next thing I can think of is how to replace the item inside the list. How I will do that?

Now that we’ve split the integer into column and row, we can assign a new variable called “new_row” which is equal to map[row -1]

new_row = map[row -1]

Then within this new_row, there are 3 columns, so if the user typed 23, our column is equal to 2, so for this reason, we can now assign the “X” mark to this new row and at column-1

new_row[column – 1] = “X”

Still confused? Why just watch what will happen when I hit the Run button?

iVisa.com

#100DaysOfCoding – Day 04 – Challenge 02

Day 04 Challenge 2 is now completed. It’s about selecting from a list of names who will be paying the bill using the Python Randomisation function.

The lesson is just 13 mins. After that, we have to complete the exercise/challenge on our own based on what we’ve understood from Day 01.

It took me half an hour to write the code, to be honest, but it’s so satisfying when you finally worked it out on your own.

Here is my code against our instructor’s code:

And here it is in action:

You know what, there is a much shorter solution here and that is by using the function called choice(), but for this exercise, we were told not to use this function and find a way to write a code that will work and give the same output.

So the code will end up like this:

I’m looking forward to the next challenge; Day 04 Challenge 03.

iVisa.com

#100DaysOfCoding – Day 04 – Challenge 01

#100DaysOfCode #100daysofcodechallenge

Just finished the Day 04 challenge about writing a virtual coin toss Python code. Don’t have a coin in hand? Why not try this Virtual Toss Coin program I’ve just created?

https://replit.com/@AllscanTwelve/day-4-1-exercise#main.py

Here is the video in action:

Virtual Toss Coin Program
Positive SSL