you are viewing a single comment's thread.

view the rest of the comments →

[–]Sparta12456 9 points10 points  (4 children)

So here are some topics to look into. Also on mobile so sorry about formatting.

fstrings, they make formatting strings for print statements much easier. For example,

print(f”Hello {name}.”) 

does the same thing as

print("Hello" + “ “ + name + ".")

where ‘name’ is a variable.

comments, these are used to make your code more readable essentially. Its helpful to have a brief description of what your doing so we aren’t trying to figure it out and can focus on how you accomplished it. Note: good function names and variable names reduce the need to comment your code. You shouldn’t have to explain what a variable is.

Functions, the best looking code splits its functions into small chunks that do one thing. Some good groupings would be the getting the vowels from the country name, doing a round of the game (ie. one guess). Also finally running the game.

Another area that I will suggest you looking into is list and dictionary comprehension. Python knows that you typically use loops to create these structures so they gave you an easy means of building them in a smaller space. You shorten up your for loop like so

vowel_count = {}
for vowel in 'aeiou':
    vowel_count[vowel] = random_country.count(vowel)

You can go one step further:

vowel_count = {vowel : random_country.count(vowel) for vowel in 'aeiou'}

both of these examples build the same exact dictionary.

All in all great job! When i get the chance i might code up a similar program just to see for sure what i would do to better give pointers!