"100 Days of Coding: Unleashing Python's Magic on Day 3 โ€“ Your Journey to Mastery"

ยท

5 min read



Introduction

"Greetings, fellow adventurers on the path to coding mastery! ๐Ÿš€ Allow me to introduce myself โ€“ I'm Aftab Ahmed, a passionate learner just like you, navigating the exciting world of coding from square one. Today marks my triumphant Day 3 in the "100 Days of Coding" challenge, and I'm thrilled to have you join me. If you're a student or an aspiring coder, you're in for a treat. We're diving into Python's captivating Control Flow and Logic โ€“ the very foundations that empower us to make computers do our bidding. So, let's lace up our coding boots and embark on this thrilling quest for knowledge and empowerment! ๐Ÿ’ก๐Ÿ’ป๐ŸŒŸ


Day 3: Unveiling Python's Control Flow and Logic Magic

Welcome back to my coding journey! Today's Day 3 of the challenge, and we're diving into the fascinating world of Control Flow and Logic. These are the secret ingredients that turn lines of code into powerful tools. Let's explore the topics that have taken me from a beginner to someone who can make computers dance to their tune.


  1. Understanding If and Else: Making Decisions with Code

Imagine you're writing instructions for a robot. You want it to do one thing if a condition is met and another thing if it's not. That's where "if" and "else" come into play. On this exciting Day 3, I learned how to make my code decide things. For example, I can tell my program to welcome you to a party if you're old enough or apologize if you're not. It's like coding with a sprinkle of magic!

age = 18
if age >= 18:
    print("Welcome to the party!")
else:
    print("Sorry, you're not old enough.")

  1. Odd or Even Numbers with Modulo: Cracking the Code

Ever wondered how a computer knows if a number is odd or even? The answer lies in a wizardly tool called the modulo operator (%). In my journey today, I found out how it works. With a dash of code, I created a program that could tell if a number you enter is odd or even. It's like giving your computer a sixth sense!

number = int(input("Enter a number: "))
if number % 2 == 0:
    print("Even")
else:
    print("Odd")

  1. Nesting the Magic: Ifs Inside Ifs

As I delved deeper into Control Flow, I discovered the power of nested "if" statements. It's like Russian nesting dolls โ€“ one decision inside another. This helps me tackle even more complex situations. Think of it as coding inception. For instance, I could code a program that determines your grade based on your test score. The possibilities are endless!

grade = 85
if grade >= 90:
    print("A")
elif grade >= 80:
    print("B")
else:
    print("C")

  1. Leap Years and Logic: Coding with Smarts

Did you know computers can tell if a year is a leap year? It's all about using logic. On Day 3, I tackled this challenge head-on. With a bit of code, I can now determine whether a year is a leap year or not. It's a bit like solving a puzzle โ€“ but way more fun!

year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
    print("Leap year")
else:
    print("Not a leap year")

  1. Rollercoaster Ticket Price: Decisions Galore

Imagine you're designing a virtual amusement park. You need to charge different prices for different age groups and heights. That's where nested "if" and "elif" statements come to the rescue. With a few lines of code, I created a program that calculates the right ticket price based on height and age. It's like being the boss of your very own theme park!

height = int(input("Enter your height in cm: "))
if height >= 120:
    print("Enjoy the ride!")
    age = int(input("Enter your age: "))
    if age < 12:
        print("Child ticket: $5")
    elif age <= 18:
        print("Teen ticket: $10")
    else:
        print("Adult ticket: $15")
else:
    print("Sorry, not tall enough to ride.")

  1. Interactive Pizza Order and Logical Operators: Code that Understands You

Coding isn't just about numbers โ€“ it's also about understanding choices. That's why we explored interactive coding, where your program chats with you! I designed a program that takes your pizza order and calculates the bill. It's like having your own digital waiter. And guess what? We also dived into logical operators โ€“ the "and" and "or" of coding that make your programs even smarter.

print("Welcome to Python Pizza!")
size = input("What size pizza do you want? S, M, or L: ")
add_pepperoni = input("Do you want pepperoni? Y or N: ")
extra_cheese = input("Do you want extra cheese? Y or N: ")

bill = 0
if size == "S":
    bill += 15
elif size == "M":
    bill += 20
else:
    bill += 25

if add_pepperoni == "Y":
    if size == "S":
        bill += 2
    else:
        bill += 3

if extra_cheese == "Y":
    bill += 1

print(f"Your total bill is ${bill}.")

  1. Spreading Love with Code: The Love Calculator

After all that coding, let's have some fun! I created a program that calculates your compatibility with someone using a love calculator. It's like coding cupid's arrow! By counting letters in your names and adding them up, the program gives you a score. Based on that score, you'll find out how compatible you are. Talk about coding with heart!

print("Welcome to the Love Calculator!")
name1 = input("What is your name? ").lower()
name2 = input("What is their name? ").lower()
combined_names = name1 + name2

true_count = combined_names.count("t") + combined_names.count("r") + combined_names.count("u") + combined_names.count("e")
love_count = combined_names.count("l") + combined_names.count("o") + combined_names.count("v") + combined_names.count("e")

total_score = int(str(true_count) + str(love_count))

if total_score < 10 or total_score > 90:
    print(f"Your score is {total_score}, you go together like coke and mentos.")
elif 40 <= total_score <= 50:
    print(f"Your score is {total_score}, you are alright together.")
else:
    print(f"Your score is {total_score}.")

Conclusion: Your Coding Odyssey Continues

And there we have it โ€“ Day 3 of my 100 Days of Coding adventure, where we conquered Control Flow and Logic. As a student and aspiring coder, this journey is about much more than just learning lines of code. It's about unleashing your creativity, making computers do your bidding, and building a powerful skill set that will shape your future. So keep coding, keep exploring, and remember โ€“ every line of code is a step closer to mastering the digital universe. Until next time, happy coding! ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป๐Ÿš€

ย