Hello everybody and welcome back to my blog. As I warned you about in the last entry I’ve been really busy with school so I haven’t had much time to dedicate on projects that I could share with you, however, as promised I have a small thing to show you that you might find interesting, though before letting you see it you need some context.
I started learning python seriously in the summer of 2019, beforehand I had done small scripts, which where all copied off tutorials, and I had some experience in programming adaptations for children, such as scratch, but nothing serious, I was 14 after all. During that summer I went to my grandparent’s house near the beach with my surface laptop and a six hour long tutorial on python’s basics by Mosh Hamedani downloaded, as the house had no WIFI. I slowly but surely advanced through the video, trying to really understand it and replicating every single step myself, while occasionally going to the cafeteria that was near to my grandparent’s house to download additional videos as they did have WIFI, this is how I ended up learning most of python’s basics.
Fast-forward some time and my surface starts experiencing some problems as I am probably putting it through things that surface laptops were not made for (intense gaming and hosting minecraft servers mostly), fast forward some more time and after some sketchy third party repairs the laptop stops working completely. I don’t remember exactly what the issue was, but it didn’t matter what we tried, the surface didn’t work, it was also pretty old by that time so it was somewhat expected. Before throwing the laptop away I told my parents to give me a screwdriver, and after a couple of questions on r/surface I managed to salvage the mSata ssd, as I didn’t want to lose my work on the computer.
The introduction to the post is dragging on a bit so I will sum the following events up. I store away the ssd and forget about its existence for a while, I get myself a PC (see the entry: Building my first Custom-Built PC), a little while ago I remember I got the ssd and think that it might be a cool idea to post my first python scripts to the blog, I find it and I try to recover it by connecting it as if it was another ssd in my computer, it doesn’t work. I submit tens of questions to r/windows and other subreddits (half of them get deleted by the auto-mod), none of the suggested fixes work. I order an ssd to USB adaptor on AliExpress (it takes ages to come), when it arrives it doesn’t work. I paid 1 EUR for it including shipping so I didn’t really have high hopes for it, I give up for a while. I try everything again, enable inheritance, give it moderator permissions, nothing. Now the computer is telling me the ssd is corrupted, this process goes on for days, until one day at 03:00 AM (I’ve pretty much given up at this point) I come across a command that can potentially fix the ssd “chkdsk /f”. I try it, it loads for a while, and boom, my file explorer is now showing me my long forgotten files from when I was 12, it finally worked. After going through a long nostalgia trip watching the videos that me and my friends took in school I finally find my PyCharm folder, and inside that folder all of my small projects that I did back then.
I cannot describe with words the rush on dopamine that I felt that night after finally fixing the ssd, and now I can finally showcase my first python scripts to you, after digging through the old ssd I found most of the programs to be small scripts off of the tutorial that I saw which were meant to teach you about python’s basic functions, but I did find a cool car game I made which can be played in the terminal.
command = ""
car_selection = ""
menu1 = ""
car_color = ""
km_to_accelerate = ""
garage_door_count = 0
speed_counter = 0
menu1_count = 0
garage_count = 0
speed_cap = 0
while_accelerate = 0
print("*You´ve entered your garage.*")
while garage_count < 1:
list_of_cars = input('Type "cars" to access to the list of your cars. ')
if str(list_of_cars.lower()) == "cars":
print('''Your cars are:
> Ferrari with a maximum speed of 300 Kms/h
> Maserati with a maximum speed of 200 Kms/h
> Lamborghini with a maximum speed of 250 Kms/h
> Bentley with a maximum speed of 180 Kms/h
> ???
''')
car_selection += input("Choose wisely: ")
if str(car_selection.lower()) == "ferrari":
speed_cap += 300
car_color = input('''Okay, in which color would you like your car?
> Red
> Yellow
> Green
> ???
>''')
if str(car_color.lower()) == "red":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "yellow":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "green":
print("Okay")
garage_count += 1
elif str(car_color) == "???":
car_color = ""
car_selection = ""
print("More cars and colors coming soon! Leave your ideas at >> miguelfserna@gmail.com << ")
else:
print(f"You don´t have a {car_color} {car_selection}")
elif str(car_selection.lower()) == "maserati":
speed_cap += 200
car_color = input('''Okay, in which color would you like your car?
> Red
> Yellow
> Blue
> ???
>''')
if str(car_color.lower()) == "red":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "yellow":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "blue":
print("Okay")
garage_count += 1
elif str(car_color) == "???":
car_color = ""
car_selection = ""
print("More cars and colors coming soon! Leave your ideas at >> miguelfserna@gmail.com << ")
else:
print(f"You don´t have a {car_color} {car_selection}")
elif str(car_selection.lower()) == "lamborghini":
speed_cap += 250
car_color = input('''Okay, in which color would you like your car?
> Red
> Purple
> Green
> ???
>''')
if str(car_color.lower()) == "red":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "purple":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "green":
print("Okay")
garage_count += 1
elif str(car_color) == "???":
car_color = ""
car_selection = ""
print("More cars and colors coming soon! Leave your ideas at >> miguelfserna@gmail.com << ")
else:
print(f"You don´t have a {car_color} {car_selection}")
elif str(car_selection.lower()) == "bentley":
speed_cap += 180
car_color = input('''Okay, in which color would you like your car?
> Black
> Grey
> Blue
> ???
>''')
if str(car_color.lower()) == "black":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "grey":
print("Okay")
garage_count += 1
elif str(car_color.lower()) == "blue":
print("Okay")
garage_count += 1
elif str(car_color) == "???":
car_color = ""
car_selection = ""
print("More cars and colors coming soon! Leave your ideas at >> miguelfserna@gmail.com << ")
else:
print(f"You don´t have a {car_color} {car_selection}")
elif str(car_selection) == "???":
car_color = ""
car_selection = ""
print("More cars and colors coming soon! Leave your ideas at >> miguelfserna@gmail.com << ")
else:
print("You do not posses that car")
car_selection = 0
car_color = 0
else:
print("You can´t do that right now")
print(f'''*You chose your {car_color} {car_selection} with a maximum speed of {speed_cap}.*''')
print('Now type "open" to open the door of your garage.')
while garage_door_count < 1:
garage_door = input(">")
if str(garage_door.lower()) == "open":
print("Opening the door")
garage_door_count += 1
else:
print('In order to drive we have to leave the garage, type "open" to open the garage door')
print('''You are now controlling your car,
type "help" for access to the command library, but first type "start" to start your engine''')
while menu1_count < 1:
menu1 = input(">")
if str(menu1.lower()) == "start":
print("Turning the engine on!")
menu1_count += 1
while str(menu1.lower()) == "start" and speed_counter < 40:
speed_counter += 1
print(f"We are now going at {speed_counter} Km/h")
else:
print('To execute any command you´ll first have to turn the engine on!, type "start" to start your engine')
while command != "quit":
command = input(">")
if str(command.lower()) == "help":
print('''
start ---- type "start" to start the engine of your car.
accelerate ---- type "accelerate" to increase your speed.
decelerate ---- type "decelerate" to decrease your speed.
speed check ---- type "speed_check" to check at how many km/h you are going.
stop ---- type "stop" to stop the engine of your car.
quit ---- type "quit" to stop the process.
''')
elif str(command.lower()) == "start" and str(menu1.lower()) != "start":
print("Turning the engine on!")
while str(command.lower()) == "start" and speed_counter < 40:
speed_counter += 1
print(f"We are now going at {speed_counter} Km/h")
elif str(command.lower()) == "stop":
print("stopping")
speed_counter -= speed_counter
print(f"We are going at {speed_counter} Km/h, we´ve stopped."
f" (if you wanna accelerate use the command accelerate,"
f" the command start will not work because we have stopped yet the engine is still on) ")
elif str(command.lower()) == "accelerate":
km_to_accelerate = input("How much Kms/h do you want to accelerate? (answer in numbers only) ")
accelerate_range = speed_counter + int(km_to_accelerate)
if str(command.lower()) == "accelerate" and int(speed_counter) > 1:
while speed_counter < speed_cap and while_accelerate < int(km_to_accelerate):
speed_counter += 1
km_to_accelerate = int(km_to_accelerate) + 1
print(f"We are now going at {speed_counter} Km/h")
else:
print("You are trying to reach more Kms/h than the Kms/h that your car can handle. ")
else:
print("We´ve reached maximum speed :( ")
elif str(command.lower()) == "decelerate":
km_to_decelerate = input("How much Kms/h do you want to decelerate? (answer in numbers only) ")
decelerate_range = speed_counter - int(km_to_decelerate)
if str(command.lower()) == "decelerate" and int(speed_counter) > 1:
while str(command.lower()) == "decelerate" and speed_counter > decelerate_range:
speed_counter -= 1
print(f"We are now going at {speed_counter} Km/h")
else:
print("We have stopped")
elif str(command.lower()) == "speed_check":
print(f"You are currently going at {speed_counter} Km/h")
elif str(command.lower()) == "quit":
print(f"*You left your {car_color} {car_selection}*")
break
else:
print("I can´t understand what are you trying to do, type help for access to the command library.")
print("Maybe you tried to start your engine when it is already on, "
"to start your engine it´ll first have to be off, maybe you tried to decelerate below 0.")
Seeing this stuff really brings up memories, I remember showing this program to my parents when they came to the beach house and my mother instantly finding a way to break it 😅 (I think I fixed it afterwards, but if you try to break it I guarantee you will find a way). Another script which I was really proud of is one that my father specifically asked me to do as a challenge, what this script does is it uses coindesk’s Bitcoin API to get Bitcoin’s price and do some stuff with it, such as just tell it to you or calculate your winnings/loses, all of this in the terminal, of course.
import requests
decision_count = 0
currency_count = 0
bitcoin_price = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
BTC = 0
earnings = 0
def bitcoin_calculated_price():
print('The current price of Bitcoin is:')
print(f"{BTC} {currency}")
while currency_count != 1:
selection = input('''Please select the currency you want to operate with
>>EUR
>>USD
>''')
if selection.lower() == 'eur':
currency = 'EUR'
BTC_EUR = bitcoin_price.json()['bpi']['EUR']['rate']
BTC_for_calc = float(BTC_EUR.replace(',', ''))
BTC += BTC_for_calc
currency_count += 1
elif selection.lower() == 'usd':
currency = 'USD'
BTC_USD = bitcoin_price.json()['bpi']['USD']['rate']
BTC_for_calc = float(BTC_USD.replace(',', ''))
BTC += BTC_for_calc
currency_count += 1
else:
print('The currency you are trying to operate with is not available.')
def bitcoin_earnings():
print(f'You have earned {earnings} {currency}')
def bitcoin_loses():
print(f'You have lost {earnings.__abs__()} {currency}')
while decision_count != 1:
decision = input('''Please select between these options:
>> Type "1" to check the price of Bitcoin in real time.
>> Type "2" to Calculate you winnings or loses.
>>Type "3" to change the currency you are operating with.
>> Type "Quit" to exit.
> ''')
if decision == '1':
bitcoin_calculated_price()
F = input('For returning to the menu type "back" if you want to exit type "quit". ')
if F.lower() == 'back':
print('Returning to the menu.')
elif F.lower() == 'quit':
break
else:
print('We could not understand what you where trying to do, returning to the menu')
elif decision == '2':
buy_price = input('Please type at what price did you buy Bitcoin. ')
quantity = input('Please tell us how many Bitcoin did you buy at that price. ')
earnings = int(quantity) * BTC_for_calc - int(quantity) * int(buy_price)
bitcoin_calculated_price()
if earnings > 0:
bitcoin_earnings()
elif earnings < 0:
bitcoin_loses()
else:
print('You have no winnings nor loses.')
elif decision == '3':
currency_count = 0
while currency_count != 1:
selection = input('''Please select the currency you want to operate with
>>EUR
>>USD
>''')
if selection.lower() == 'eur':
currency = 'EUR'
BTC_EUR = bitcoin_price.json()['bpi']['EUR']['rate']
BTC_for_calc = float(BTC_EUR.replace(',', ''))
BTC += BTC_for_calc
BTC /= 2
currency_count += 1
elif selection.lower() == 'usd':
currency = 'USD'
BTC_USD = bitcoin_price.json()['bpi']['USD']['rate']
BTC_for_calc = float(BTC_USD.replace(',', ''))
BTC += BTC_for_calc
BTC /= 2
currency_count += 1
else:
print('The currency you are trying to operate with is not available.')
elif decision.lower() == 'quit':
break
else:
print('We could not understand what you where trying to do.')
Apart from these two scripts I don’t think there’s much more worth showing, there are some scripts which manipulate an excel sheet which I didn’t remember anything about, some machine learning attempts which went catastrophically bad, and the many basic scripts from the tutorial that I already mentioned.
Digging through my old projects was a really cool experience as I got to see how my coding skills have evolved overtime, and how I still maintain some mannerisms from when I first learnt python that I should try to improve on. Apart from that there’s not much more to say, I just wanted to upload something to the blog so that you guys don’t think I’ve died, and you got to learn something about how I started coding, I hope you found this entry somewhat interesting, and until the next time!

Leave a comment