How to add in case validation in a text based game - python

I'm using pycharm to write the code
I'm making a text based game for a school project and have pretty much finished. However, my instructor recommended I add case validation for the input for better UX. I can't for the life of me figure it out.
She's asking that i make it so the user can input the direction with different letter cases.
as of right now only west, east, south, north are valid inputs, all lowercase. How can I can add case validation?
dictionary
movement
I tried changing the dictionary to 'west' or 'West' and adding 'West' to the list of directions. That didn't even make West a valid input. I'm at a loss.

if you want the easy way, go with the .lower() function, it turns every uppercase work into a lowercase word.
however, you could also try to implement it on your own by making an array of lowercase letters and an array of uppercase letter, and then replacing every upper by it's lower counterpart

Related

Add Solver Constraint For Non-Mutually Exclusive Ranges

I use or-tools to optimize my fantasy baseball team. My setup very much resembles the program described here. The only difference in my particular case is that players can actually be eligible for a number of different positions. So, I end up with 1 player in a list for a specific position type, and the same player in another list for another position type. I am trying to avoid having the solver select the same player for multiple positions (which wouldn't be realistic).
Is there any way to modify the aforementioned program to constrain the use of a player to a single position even while they are technically eligible for many? Please let me know if I can clarify any further & thanks for your input.

Shorten words and strings to specific length in Python keeping them as recognizable as possible?

I'm trying to render a lot of different strings on a 32x32px canvas. Currently I'm trying to use pyvips but it lacks support for character wrap in Pango. Thus, for now I'm trying to shorten separate words. The desired word length limit is about 8 characters most of the time.
Simple disemvowelment doesn't work when the word is starting with a vowel or has repeating vowels. I guess additional cut can be done by deduplicating characters. But the main problem is the lack of algorithm / heuristic for deciding what's less important, should be removed first and stopping at certain word / string length. The task seems so common that I'd expect there being some library already available. However I cannot find it: disevowel and shorten searches didn't yield anything useful.
For example, if I wanted to shorten Eerie Aaron and an aardvark to 20 characters, I'd go with something like Erie Aron and ardvrk.
Also, I've seen it implemented in the Draft Fortress game, but it's closed-source.

Algorithm to find one edit distance words from input word using Levenshtein distance?

I have a dictionary which has so much words in it(Approximately 100000). I am taking one word from user which is wrote wrong. For example this word is "andd". User always write wrong and with one edit distance. My program scan all the dict and find all 1 edit distance words and according to their usage rates, return true correct spelling. For example it finds and, andy, ande. After that calculate usage rate and return one of them.
However my program works very slowly when I take 300 words from user. Therefore I want to change my code. Firstly, I want to create all words with edit distance 1 from given word and check which ones in the dict. If word in the dict, I will calculate usage rate again and return it.
With this way, my program don't control edit distance for every word in the dict.
Briefly, I want to create all combinations with edit distance 1 from given input word. Should I add the whole alphabet and try it everywhere, or does it have an algorithm? I couldn't find anything on the internet. Thank you everyone.

How do I create a Leaderboard using a text file in python?

I'm working on a quiz for my exam in computer science. I'm relatively new to the program, in the sense that I know all of the basics, but I am on the point where I want to expand my knowledge. One way I want to do this is by adding a Leaderboard system. The user gets a number of points, and then the program checks in a text file that has other high scores in it, and adds the user to it. It then prints out the leaderboard. This means that I'm going to have to use some sort of operations to determine whether the user's score is higher or lower than another score in the file, and then delete the score it is higher than and replace it. Any idea on how to do this? I'm completely stuck.
Try Pseudeocode and work through steps.
Get Score
Compare Score
Add Score
You have to think like a computer and break all the way down. At each step think about how do I tell the computer to do that. Once you have all that look at what you have done and remember DRY -> Don't Repeat Yourself. Your coding will go much faster.

How to generate homophones on substring level?

I want to generate homophones of words programmatically. Meaning, words that sound similar to the original words.
I've come across the Soundex algorithm, but it just replaces some characters with other characters (like t instead of d). Are there any lists or algorithms that are a little bit more sophisticated, providing at least homophone substrings?
Important: I want to apply this on words that aren't in dictionaries, meaning that I can't rely on whole, real words.
EDIT:
The input is a string which is often a proper name and therefore in no standard (homophone) dictionary. An example could be Google or McDonald's (just to name two popular named entities, but many are much more unpopular).
The output is then a (random) homophone of this string. Since words often have more than one homophone, a single (random) one is my goal. In the case of Google, a homophone could be gugel, or MacDonald's for McDonald's.
How to do this well is a research topic. See for example http://www.inf.ufpr.br/didonet/articles/2014_FPSS.pdf.
But suppose that you want to roll your own.
The first step is figuring out how to turn the letters that you are given into a representation of what it sounds like. This is a very hard problem with guessing required. (eg What sound does "read" make? Depends on whether you are going to read, or you already read!) However text to phonemes converter suggests that Arabet has solved this for English.
Next you'll want this to have been done for every word in a dictionary. Assuming that you can do that for one word, that's just a script.
Then you'll want it stored in a data structure where you can easily find similar sounds. That is in principle no difference than the sort of algorithms that are used for autocorrect for spelling. Only with phonemes instead of letters. You can get a sense of how to do that with http://norvig.com/spell-correct.html. Or try to implement something like what is described in http://fastss.csg.uzh.ch/ifi-2007.02.pdf.
And that is it.

Categories

Resources