100 Days of Code Challenge: Day 3
Tags: 100daysofcode, python, csharp
Published: 2023-01-06 18:16:21

For Day 3 of the Python Pro Bootcamp, I learnt about conditional logic ( if-else, elif, nested if statements), logical operators (and, or) and string concatenation. I did a lot of exercises for day 3 (yesterday and today) but the projects I focused on the most are the love calculator project and the treasure island adventure game.

Love Calculator Python code:

```
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
combined_names = name1 + name2
lowercase = combined_names.lower()
t = lowercase.count("t")
r = lowercase.count("r")
u = lowercase.count("u")
e = lowercase.count("e")
true = t + r + u + e
l = lowercase.count("l")
o = lowercase.count("o")
v = lowercase.count("v")
e = lowercase.count("e")
love = l + o + v + e
love_score = int(str(true) + str(love))
print(love_score)
if love_score < 10 or love_score > 90:
    print(f"Your love score is {love_score}, you go together like coke and mentos.")
elif love_score >= 40 and love_score <= 50:
    print(f"Your love score is {love_score}, you are alright together.")
else:
    print(f"Your love score is {love_score}.")
```

I tried recreating the Love Calculator in C# but trying to return a number of occurrences of a substring in a string is more complex in C# as it involves using multiple parameters and the syntax isn't as simple as Python's e.g. stringvariable.count("a"). 

Treasure Island Python code:

```
print('''
*******************************************************************************
          |                   |                  |                     |
 _________|________________.=""_;=.______________|_____________________|_______
|                   |  ,-"_,=""     `"=.|                  |
|___________________|__"=._o`"-._        `"=.______________|___________________
          |                `"=._o`"=._      _`"=._                     |
 _________|_____________________:=._o "=._."_.-="'"=.__________________|_______
|                   |    __.--" , ; `"=._o." ,-"""-._ ".   |
|___________________|_._"  ,. .` ` `` ,  `"-._"-._   ". '__|___________________
          |           |o`"=._` , "` `; .". ,  "-._"-._; ;              |
 _________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
|                   | |o;    `"-.o`"=._``  '` " ,__.--o;   |
|___________________|_| ;     (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._    "      `".o|o_.--"    ;o;____/______/______/____
/______/______/______/_"=._o--._        ; | ;        ; ;/______/______/______/_
____/______/______/______/__"=._o--._   ;o|o;     _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
''')
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
firstchoice = input("You are at a crossroad. Where do you want to go? Type 'left' or 'right'.\n").lower()
if firstchoice == "left":
    secondchoice = input("You have come to a lake. There is an island in the middle of the lake. Type 'wait' to wait "
                         "for a boat or type 'swim' to swim across. \n").lower()
    if secondchoice == "wait":
        thirdchoice = input("You arrive at the island unharmed. There is a house with three doors. One red, one yellow"
                            "and one blue. Which colour do you choose? \n").lower()
        if thirdchoice == "red":
            print("This room is full of fire. Game over!")
        elif thirdchoice == "yellow":
            print("You found the treasure. You win!")
        elif thirdchoice == "blue":
            print("You enter a room full of piranhas. Game over!")
        else:
            print("This door doesn't exist. Game over!")
    else:
        print("You drowned. Game over!")
else:
    print("You fall into a sinkhole. Game over!")
```

The above code was a simple adventure game that gives the users 3 choices before determining if they win the game or if they lose, depending on their choice. 

Treasure Island C# code:

```
Console.WriteLine("Welcome to Treasure Island!");
Console.WriteLine("Your mission is to find the treasure.");
string firstchoice;
string secondchoice = "";
string thirdchoice = "";
Console.WriteLine("You are at a crossroad. Do you go left or right? Type 'left' or 'right'.");
firstchoice = Console.ReadLine().ToLower();
if (firstchoice == "left")
{
    Console.WriteLine("You have come to a lake. There is an island in the middle of the lake. " +
        "Type 'wait' to wait for a boat or 'swim' to swim for it.");
    secondchoice = Console.ReadLine().ToLower();
} else
{
    Console.WriteLine("You fall into a sinkhole. Game over!");
}
if (secondchoice == "wait")
{
    Console.WriteLine("You arrive at the island unharmed. There is a house with 3 doors: one red," +
        "one yellow and one blue. Which colour door do you enter?");
        thirdchoice = Console.ReadLine().ToLower();
} else
{
    Console.WriteLine("You drowned. Game over!");
}
if (thirdchoice == "red")
{
    Console.WriteLine("This room is full of fire. Game over!");

} else if (thirdchoice == "yellow")
{
    Console.WriteLine("You found the treasure. You win!");
} else if (thirdchoice == "blue")
{
    Console.WriteLine("You enter a room full of piranhas. Game over!");
```
I managed to convert the Python code to C# as it mostly involves if statements and the syntax for that is similar in both programming languages, the main difference being C# uses curly braces while Python uses a colon. 

I am going to continue with Day 4 next week.