Python Forum
Guessing Game with .WAV Files - Python Coding
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guessing Game with .WAV Files - Python Coding
#5
Actually, instead of tuples, you can use your dictionary. I'd replace your loop like so (untested)
# this only need to be defined once (not in the loop); I use sounds.keys() instead of a separate tuple
sounds = {"A7": A7, "Amaj": Amaj, "Amin": Amin, "Amin7": Amin7, "Cmaj": Cmaj, "D7": D7, "Dmaj": Dmaj, "E7": E7, "Emaj": Emaj, "Emin": Emin, "Emin7": Emin7, "Gmaj": Gmaj}

while True:
    choice = random.choice(sounds.keys())
    winsound.PlaySound(choice, winsound.SND_FILENAME|winsound.SND_ASYNC)
    print("A7, Amaj, Amin, Amin7, Cmaj, D7, Dmaj, E7, Emaj, Emin, Emin7, Gmaj")
    guess = input("What sound was just played?: ")
 
    if sounds.get(guess) == choice:
        print("Well done!")
    else:
        print("Try again.")
The alternative with tuples is a list of pairs instead of a dictionary. You'd use random.choice() on the list, and get a pair containing the sound path and the expected guess string. You could then use that. I think a list of tuples is slightly simpler, but it's up to you what you want to stick to.
Reply


Messages In This Thread
RE: Guessing Game with .WAV Files - Python Coding - by micseydel - Nov-11-2018, 11:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Beginner Boolean question [Guessing game] TKB 4 2,568 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Unable to count the number of tries in guessing game. Frankduc 7 2,155 Mar-20-2022, 08:16 PM
Last Post: menator01
  Tic-Tac game (Beginner's coding) Shahmadhur13 5 3,375 Aug-29-2020, 08:40 PM
Last Post: deanhystad
  Guessing game problem IcodeUser8 7 3,943 Jul-19-2020, 07:37 PM
Last Post: IcodeUser8
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,982 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Python Help - Guessing Game JamieT 5 2,955 Apr-16-2020, 01:30 PM
Last Post: deanhystad
  Guessing game kramon19 1 2,294 Mar-25-2020, 04:17 AM
Last Post: deanhystad
  Help for guessing game code Kronos 5 3,495 Mar-09-2020, 04:53 PM
Last Post: snippsat
  guessing the number game go127a 6 5,057 Apr-27-2019, 01:23 PM
Last Post: go127a
  Guessing Game does not work the_entrepreneur 3 2,960 Apr-20-2019, 06:19 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020