+ 3

I need help with a game that should be created with PYTHON.

Write a program to play the following game. There is a list of several country names and the program randomly picks one. The player then has to guess letters in the word one at a time. Before each guess the country name is displayed with correctly guessed letters filled in and the rest of the letters represented with dashes. For instance, if the country is Canada and the player has correctly guessed a, d, and n, the program would display -anada. The program should continue until the player either guesses all of the letters of the word or gets five letters wrong

14th Jul 2022, 8:42 AM
Adekunle Oluwatosin Habeeb
Adekunle Oluwatosin Habeeb - avatar
7 Réponses
+ 3
Interesting. How much of it have you completed?
14th Jul 2022, 8:58 AM
Chris Coder
Chris Coder - avatar
+ 2
Chris Coder I imported the module (random) and I have been able to randomize the countries. Asked a user for his/her guess for 5 trials. Now the issue is replacing the letters that are not guessed with a dash (-)
14th Jul 2022, 9:24 AM
Adekunle Oluwatosin Habeeb
Adekunle Oluwatosin Habeeb - avatar
+ 2
Well that is some progress. You can modify and learn from this code. https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-program-for-word-guessing-game/
14th Jul 2022, 9:44 AM
Chris Coder
Chris Coder - avatar
+ 2
Create a list from country name, use map() to change selective characters in the list (ones that are in user_guessed_letters string). Then glue the map() result back to string using string::join().
14th Jul 2022, 9:49 AM
Ipang
+ 2
Ipang I was wondering if map would work. I tried to program it and then I ended up having a similar code to geeksforgeeks.
14th Jul 2022, 9:54 AM
Chris Coder
Chris Coder - avatar
+ 2
Chris But why wouldn't map() work? I tried it using the OP's example - country: "Canada" and got "-anada" in the end.
14th Jul 2022, 9:59 AM
Ipang
+ 2
Thanks to everyone for the help. It was really helpful. Currently studying the code.
14th Jul 2022, 10:20 AM
Adekunle Oluwatosin Habeeb
Adekunle Oluwatosin Habeeb - avatar