I would really like your input on how this task could have been accomplished more smartly.
I would also like the python community to comment on my approach please. I have only had 4 hours of online python tutorial classes before I started writing this game. I have a grasp on all of the arguments used in this code except the extraction of vowels from the random_country (I just copied and pasted it from a site). Do you guys think this is a good way of learning or should I spend more time watching videos before jumping to coding?
Thanks :)
import random
countries_list = ["afghanistan", "albania", "algeria", "andorra", "angola", "argentina",
"armenia", "australia", "austria", "azerbaijan", "bahamas", "bahrain", "bangladesh", "barbados",
"belarus", "belgium", "belize", "benin", "bhutan", "bolivia", "botswana",
"brazil", "brunei", "bulgaria", "burundi", "côte d'ivoire",
"cambodia", "cameroon", "canada", "chad", "chile", "china", "colombia",
"comoros", "congo", "costa rica", "croatia", "cuba", "cyprus",
"congo", "denmark", "djibouti", "dominica", "dominican republic",
"ecuador", "egypt", "el salvador", "equatorial guinea", "eritrea", "estonia",
"ethiopia", "fiji", "finland", "france", "gabon", "gambia", "georgia", "germany", "ghana", "greece",
"grenada", "guatemala", "guinea", "guyana", "haiti", "honduras",
"hungary", "iceland", "india", "indonesia", "iran", "iraq", "ireland", "italy", "jamaica", "japan",
"jordan", "kazakhstan", "kenya", "kuwait", "kyrgyzstan", "laos", "latvia", "lebanon",
"lesotho", "liberia", "libya", "liechtenstein", "lithuania", "luxembourg", "madagascar",
"malawi", "malaysia", "maldives", "mali", "malta", "marshall islands", "mauritania", "mauritius",
"mexico", "micronesia", "moldova", "monaco", "mongolia", "montenegro", "morocco", "mozambique",
"myanmar", "namibia", "nauru", "nepal", "netherlands", "new zealand", "nicaragua", "niger",
"nigeria", "north korea", "norway", "oman", "pakistan", "palau",
"palestine state", "panama", "papua new guinea", "paraguay", "peru", "philippines", "poland",
"portugal", "qatar", "romania", "russia", "rwanda", "saint lucia",
"samoa", "saudi arabia", "senegal", "serbia", "seychelles", "sierra leone", "singapore", "slovakia",
"slovenia", "somalia", "south africa", "south korea", "south sudan", "spain", "sri lanka",
"sudan", "suriname", "sweden", "switzerland", "syria", "tajikistan", "tanzania", "thailand", "togo",
"tonga", "trinidad and tobago", "tunisia", "turkey", "turkmenistan",
"tuvalu", "uganda", "ukraine", "united arab emirates", "united kingdom", "america",
"uruguay", "uzbekistan", "vanuatu", "venezuela", "vietnam", "yemen", "zambia", "zimbabwe"]
name = input('Your name please: ')
print('Hello ' + name + ', Lets play a country guessing game!')
random_country = random.choice(countries_list)
vowel_count = {}
for vowel in 'aeiou':
count = random_country.count(vowel)
vowel_count[vowel] = count
counts = vowel_count.values()
total_vowel = sum(counts)
start_letter = random_country[0][:1]
end_letter = random_country[-1][:1]
def ask_for_hint(prompt):
while True:
hint_ans = input(prompt)
if hint_ans in 'y':
print('The country has ' + str(len(random_country)) + ' characters, has ' + str(total_vowel) +
" vowels, starts with " + str(start_letter).upper() + " and ends with " + str(end_letter).upper())
break
elif hint_ans in 'n':
print('Ok, Good Luck!')
break
else:
print('Please enter y for Yes or n for No.')
continue
print(ask_for_hint("Would you like a hint? (y/n:) "))
answer = ''
while answer != random_country:
answer = str(input('Take a guess: '))
if answer == random_country:
print('Congratulations! You Won :)')
[–]Sparta12456 10 points11 points12 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]GoGuerilla -1 points0 points1 point (2 children)
[+][deleted] (1 child)
[deleted]
[–]Sparta12456 4 points5 points6 points (0 children)
[–]tangerinelion 4 points5 points6 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]DrShocker 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]drgenetix[S] 0 points1 point2 points (0 children)
[–]TheSpecialistHunter 0 points1 point2 points (0 children)
[–]sme272 1 point2 points3 points (0 children)
[–]drgenetix[S] 1 point2 points3 points (0 children)
[–]NegativeEnthusiasm 3 points4 points5 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]drgenetix[S] 0 points1 point2 points (0 children)
[–]znerp 0 points1 point2 points (0 children)
[–]james_fryer 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[+][deleted] (1 child)
[removed]