this post was submitted on 01 Mar 2025
142 points (100.0% liked)

Programming

18667 readers
299 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

note: i did NOT create the ASCII art. I'm not good enough to do that. I found on various ascii art archives as well as those image to ascii art converters for the continents I couldn't find.

countryguess was a project I made recently because I wanted to make a quiz that could be customised as you see fit. Also, I had no clue how to make GUIs with Python and ASCII art is cool so I decided to roll with it. It turned out pretty cool!

I made the maps by printing the ASCII art map, and then all the spaces that make up each country would be an array. These arrays would fill up the spaces like morocco[0], morocco[1], etc.

Then, when the country is guessed, the country (or an alternate name/abbrviation, such as uk for the united kingdom or ivory coast for cote d'ivoire) is matched with its index in the list of countries in that continent.

A second list contains all the countries that show up on the map (excluding citystates, islands, etc. that aren't big enough to be shown on the map) and has all the countries as either 0 (false) or 1 (true). Whenever the country is guessed, its respective list item turns into 1.

The map printing function checks each list item for whether it is true or false. If it is true, then the list of spaces for that country would be replaced with a list of equal length and equal number of characters but with hashes "#" instead of spaces " ". This means that, when the county is printed, hashes are printed instead of spaces and the country fills up

I've got africa, europe, north america, and oceania completed. I haven't yet made the map for asia because it's HUGE, and south america I haven't done yet as well. Also, central/eastern europe is VERY out of proportion and will be fixed...eventually. (i.e. long romanian panhandle)

other fun features I added include the ability to enable/disable disputed territories (Western Sahara, Kosovo, and Somaliland bc why not) and the U.N. observer states (the Vatican and Kosovo) as well as score saving to a "scores.txt" that shows the date, time, and name of quiz that you complete along with your score.

once I finished all the continents, I'll work on making a world quiz with ALL the countries. other things like capital quizzes and flag quizzes could be added on later, but that's likely very far into the future.

here are some more screenshots:

europe europe

oceania oceania

north america north america

the github link if you want to look at the code or just have a go at the quiz: https://github.com/swarbler/countryguess

top 38 comments
sorted by: hot top controversial new old

I've created a PR for this to be added to nixpkgs: https://github.com/NixOS/nixpkgs/pull/387174

[–] ethancedwards8@programming.dev 3 points 6 days ago (1 children)

Have you considered adding a license to your repository so that it can be packaged in repositories? And a pyproject.toml or setup.py? That would help us in nixpkgs specifically

[–] scheep@lemmy.world 2 points 6 days ago (1 children)
[–] ethancedwards8@programming.dev 1 points 5 days ago (1 children)

Well, adding a code license alllows other people to use your code. Technically now, you reserve all rights to your code and it is illegal for us to look at it or use it.

Those other two make it easier to manage dependencies and setup python virtual environments. Additionally, they allow the package to be more easily to software repositories like Nixpkgs or Debian or Arch. It’s also just an industry standard. Poetry has been used to manage pyprojects for years, but uv is a popular tool too and what I use.

[–] scheep@lemmy.world 2 points 5 days ago (1 children)

oh okay, what's the best license? what's the difference between CC, MIT, etc.

I'll look at setting up python virtual environments later, they seem pretty important to at least learn how to use

[–] ethancedwards8@programming.dev 2 points 5 days ago* (last edited 5 days ago) (1 children)

CC, depending on which version you choose, is pretty much open domain. I personally would stay away from it for code, but there isn’t really anything wrong with it. MIT is also pretty permissive, but derivative copies of your work need to acknowledge that you wrote the code. GPL is something called Copyleft. It protects both you, your users, and your code to the highest degree. You retain the copyright but also anyone who takes your work and modifies it must also give their source code with the program. I’m simplifying here some, but I recommend you look up the definition of Copyleft licenses, its history, and why the GPL is so important. I emphatically recommend that you choose the GPLv3. But in all reality, there is no “best”. It depends on what matters to you and how you want the code to be used.

It is definitely an important topic to learn about. To be honest, I’m surprised you programmed as far as you did without knowing about them. Great work.

[–] scheep@lemmy.world 1 points 5 days ago

ok, I see. It seems that MIT let you do whatever with the code, whereas GPL seems like the same thing, but with an * that any derivatives must be open-source as well. I'll put the license on my repos then.

[–] SwordInStone@lemmy.world 2 points 6 days ago

Regarding the dependencies you might want to check out https://rye.astral.sh/

[–] tal@lemmy.today 32 points 1 week ago* (last edited 1 week ago) (2 children)

note: i did NOT create the ASCII art. I’m not good enough to do that. I found on various ascii art archives as well as those image to ascii art converters for the continents I couldn’t find.

FYI:

$ telnet mapscii.me

Zoom is "a" and "z", arrow keys pan, "q" quits.

e.g.:

Can produce a map of wherever at whatever zoom.

[–] scheep@lemmy.world 9 points 1 week ago

oh damn that's kinda cool

[–] Andromxda@lemmy.dbzer0.com 3 points 1 week ago

This is so cool!

[–] morrowind@lemmy.ml 13 points 1 week ago (1 children)
Traceback (most recent call last):
  File "<redacted>\countryguess\countryguess.py", line 3, in <module>
    from art import *
ModuleNotFoundError: No module named 'art'

you might want to add a requirements.txt

[–] scheep@lemmy.world 6 points 1 week ago (1 children)

oop yep that's probably important. I've added that to the repo!

[–] morrowind@lemmy.ml 10 points 1 week ago (2 children)

wow that's... quite a list. Are you sure you need them all? What are you using like redis, yt-dlp or spotifyapi, ytmusicapi for??

[–] scheep@lemmy.world 7 points 1 week ago (3 children)

oh wait shoot did it just add all the modules installed on my computer...damn... how do I make a proper requirements.txt? that pip command definitely didn't do it...

[–] Dunstabzugshaubitze@feddit.org 6 points 1 week ago (1 children)

have a look at venv for your future projects :) there is also some tooling to help with all the warts around python and packaging.

last bigger python project i was part of used poetry, but it's been ages, so there is probably a new cool thing i am not aware of.

[–] SwordInStone@lemmy.world 1 points 6 days ago
[–] IanTwenty@lemmy.world 4 points 1 week ago (1 children)

Are you using a virtual env to isolate the environment of the game from the rest ofyour system? There are a few ways/tools to do it but maybe start here:

https://docs.python.org/3/library/venv.html

[–] scheep@lemmy.world 1 points 1 week ago (3 children)

is venv important/neccesary?

[–] IanTwenty@lemmy.world 2 points 6 days ago (1 children)

It's a bit like using directories/folders to organise your work - you don't have to have separate projects in separate folders but it really helps the more projects you have going on. Also once you have two Python projects that require different versions of the same dependency things will get messy.

[–] scheep@lemmy.world 2 points 6 days ago

oh yep that makes sense

[–] SwordInStone@lemmy.world 1 points 6 days ago
[–] runeko@programming.dev 5 points 1 week ago (1 children)

Neccessary? No. You showed that by coding this with your main python environment. Important? Yes. Using a project specific virtual python environment allows you to only use the modules needed and protects your main environment from malware packages and incompatible packages that could not play well with your OS and other projects you are working on.

[–] scheep@lemmy.world 3 points 1 week ago

oop okay maybe my next project should use a virtual python enviornment then

[–] morrowind@lemmy.ml 1 points 1 week ago

ok haha, I guessed something like that must've happened

[–] scheep@lemmy.world 3 points 1 week ago

ok I fixed it, it should just be "art" (a library to make ascii art) and "colorama" (easier coloured text)

[–] scheep@lemmy.world 6 points 1 week ago

another upside to this quiz over things like Sporcle is that since it's a python program, you don't need an internet connection to play it.

[–] scheep@lemmy.world 3 points 1 week ago

besides weird central/eastern europe chaos, there's also no islands that are highlighted at all in north america, not even the big ones like cuba or haiti/dominican republic. I will probably add those at some point, but that'll be later.

[–] Andromxda@lemmy.dbzer0.com 2 points 1 week ago (1 children)
[–] scheep@lemmy.world 2 points 1 week ago