Intro quiz made using Python and VLC before, but when I tried this with a friend on Discord, it was more than I expected. The quiz was good. While everyone enjoyed it, I was dissatisfied with the actual play, so I tried to improve that point. Gist of the code before improvement is here Click here for the improved code Gist (https://gist.github.com/Qman11010101/ec771a34bab5cb815ebd83c1bd203df9)
Same as the previous one. Python: 3.8.2 python-vlc: 3.0.7110 VLC Media Player: 3.0.8 Vetinari
I will list the points that were actually pointed out or that I found inconvenient when playing. It is numbered for convenience so that we can compare it with the problem and describe the improvement points later.
When I was doing the quiz, I sometimes received a request to "play it again", but I couldn't because I didn't implement it.
For example, there is a song called "Nirv lucE". When this song is correct, "nirv luce" and "Nirv lucE" will be judged as incorrect. Even in the program before the improvement, perfect (exact match) and correct answer (partial match) were separated, but I thought that it would be no problem that the correct answer would be treated as a complete incorrect answer due to the difference in case.
This program was originally made for playing alone, so there was no problem, but when playing with everyone, it is time to give the correct answer or give up and then be happy or regretted to see the correct answer I wanted.
In rare cases, the intro would move to the answer input screen without the music starting.
There was a problem that it became boring because I gradually remembered it because a fixed part flowed for a fixed time.
In order to prevent the correct answer by entering only one character in the song title, I tried to input at least 3 characters (despite the fact that it corresponds to the explanation). ) Even if I input the song title of 2 characters or less correctly, I got the judgment that "the number of input characters is too small".
Contrary to Problem 6, even a long song title (for example, "a consideration of a fantastic world view in me and an event in a certain reality that reminded me of its manifestation") is "in me" and "the world" There was a loophole that would be treated as a correct answer if you entered "view" and "event". There aren't many songs with very long titles, but I didn't want these loopholes to remain.
We will solve the seven problems listed above.
In order to implement the hint function while solving problem 1, we made it possible to type commands on the song title input screen.
I decided to treat strings starting with _
as commands.
I chose the underscore as the prefix simply because I didn't think there was a song title that started with the underscore (because there is something like "!!! Chaostime !!!" for !
).
We have incorporated give-up and hint functions into this command system.
Below is a list of the commands actually implemented.
--_giveup
: Give up function. Enter when you don't know the answer.
--_replay
: Replay function. Play again.
--_length
: Display the length of the song title.
--_letter
: Display the first character of the song title.
This image actually uses the command function. I use it in the 5th song.
The command is structured so that it can be added freely, so it is possible to further enhance the hints.
To solve problem 2, the entered alphabet is converted to lowercase.
I used the lower ()
method that comes with Python.
However, I try to keep the original correct song title for perfect judgment.
For details, please see the code uploaded to Gist.
lower ()
and the original song title with lower ()
.
3.2 If it is False, it is judged to be incorrect.It is judged by the procedure.
This simply put in ʻinput ()so that I had to press Enter to go to the next song. At first I was thinking about using
time.sleep ()`, but I realized that I didn't need to set the time here to a fixed length, so I implemented it like this.
In order to solve problems 4 and 5 together, the song is played from a random point in the middle instead of the intro. In addition, the playback time is also randomly selected from 3 seconds to 7 seconds so that high difficulty and low difficulty can be mixed in a well-balanced manner.
Problems 6 and 7 will be explained together. Paste the code for the relevant part below.
#Length judgment unit
if len(answer) >= min(len(music_name)//3, len(music_name_lower)):
#Correct answer judgment unit
if answer == music_name:
print("Perfect! amazing!")
break
elif answer_lower in music_name_lower:
print("Correct answer! Congrats!")
break
else:
print("Sorry! Incorrect answer!")
else:
print("There are too few characters to enter!")
As you can see in the second line, the condition has been changed from "3 characters or more" to "1/3 or more of the song title" (solving problem 7). Also, by doing this, even if the song title is one character, it works normally (solving problem 6).
Occasionally, the song doesn't play and I get this kind of error, but I don't know the cause and I've left it for now.
Nowadays, I often play this music quiz with my friends on Discord, so I want to make the judgment a little easier by putting the answers entered by my friends into the program as they are. At this point I have to copy and paste everyone's answers on my own.
I want to set how many songs to play first and set the upper limit that can be answered.
There is a song called "TiamaT: F minor", but since :
is a character that cannot be used in file names, it has been replaced with notations such as TiamaT-F minor
and TiamaTF minor
.
The song title set in the file itself is correct, so I would like to use that for judgment.
I ended up with a music quiz instead of an intro quiz, but I'm happy because I'm less bored. I would also like to purchase a CD to increase the variety of songs and play.
Recommended Posts