Try to improve your own intro quiz in Python

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)

environment

Same as the previous one. Python: 3.8.2 python-vlc: 3.0.7110 VLC Media Player: 3.0.8 Vetinari

Dissatisfaction point

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.

1. Cannot replay

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.

2. Strictly case sensitive

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.

3. The next song starts immediately after the correct answer is displayed

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.

4. Some songs have a long silent section in the intro

In rare cases, the intro would move to the answer input screen without the music starting.

5. If you do it many times, everyone will remember it

There was a problem that it became boring because I gradually remembered it because a fixed part flowed for a fixed time.

6. There was a partial judgment bug

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".

7. There was an example where I entered a little and got the correct answer.

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.

Improvement

We will solve the seven problems listed above.

1. Implement the command system

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. スクリーンショット 2020-09-07 14.31.09.png

The command is structured so that it can be added freely, so it is possible to further enhance the hints.

2. Unify letters to lowercase and eliminate spaces

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.

  1. Make a perfect judgment by comparing the input character string with the original song title.
  2. When 1 is False The correct answer is judged by comparing the input character string with 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.

3. Set an interval between the next song

This simply put in ʻinput ()so that I had to press Enter to go to the next song. At first I was thinking about usingtime.sleep ()`, but I realized that I didn't need to set the time here to a fixed length, so I implemented it like this.

4/5. Playback part / time was randomized

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.

6/7. Judgment is made by the ratio to the number of correct characters

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).

What I couldn't / want to improve / fix

Sometimes an error occurs

スクリーンショット 2020-09-07 14.31.18.png 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.

I want to work with Discord

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 the maximum number of times

I want to set how many songs to play first and set the upper limit that can be answered.

I want to get the song title directly instead of the file name

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.

Summary

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

Try to improve your own intro quiz in Python
Try to put LED in your own PC (slightly)
[Road to intermediate Python] Define in in your own class
[Python] logging in your own module
Try to calculate Trace in Python
Try sorting your own objects with priority queue in Python
Try HeloWorld in your own language (with How to & code)
Try logging in to qiita with Python
Create your own Linux commands in Python
[LLDB] Create your own command in Python
Easily use your own functions in Python
Try to log in to Netflix automatically using python on your PC
Try text mining your diary in Python
Get your own IP address in Python
Try to make your own AWS-SDK with bash
First steps to try Google CloudVision in Python
Try to calculate a statistical problem in Python
3.14 π day, so try to output in Python
Try auto to automatically price Enums in Python 3.6
How to define your own target in Sage
Try to calculate RPN in Python (for beginners)
Import your own modules in Grasshopper's Python development
Try gRPC in Python
Try 9 slices in Python
Create your own Big Data in Python for validation
Try to make a Python module in C language
[Introduction to Udemy Python 3 + Application] 66. Creating your own exceptions
Use the CASA Toolkit in your own Python environment
To flush stdout in Python
Try to understand Python self
Login to website in Python
Try LINE Notify in Python
Speech to speech in python [text to speech]
Try implementing Yubaba in Python 3
How to develop in Python
Post to Slack in Python
Try to make it using GUI and PyQt in Python
How to use pyenv and pyenv-virtualenv in your own way
Just try to receive a webhook in ngrok and python
[Python] When you want to import and use your own package in the upper directory
Try to make a blackjack strategy by reinforcement learning (③ Reinforcement learning in your own OpenAI Gym environment)
[Python] Make your own LINE bot
Convert markdown to PDF in Python
Try to get a list of breaking news threads in Python.
How to collect images in Python
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
Try to operate Facebook with Python
Try implementing extension method in python
How to use SQLite in Python
How to create your own Transform
Try using LevelDB in Python (plyvel)
Try implementing k-NN on your own
Let's try Fizz Buzz in Python
In the python command python points to python3.8
[Cloudian # 2] Try to display the object storage bucket in Python (boto3)
Create your own graph structure class and its drawing in python
Try docker: Create your own container image for your Python web app
Try PLC register access in Python
Try to put data in MongoDB
Try converting cloudmonkey CLI to python3 -1
How to use Mysql in python