Code Monkey home page Code Monkey logo

python-projects's People

Contributors

maliciousfiles avatar mrmaxguns avatar

Stargazers

 avatar

Watchers

 avatar  avatar

python-projects's Issues

Madlib program not allowing the template to have identical parts of speech

Madlib program not allowing the template to have identical parts of speech

Expected Behavior

If you create a template with two or more parts of speech, such as two different nouns, the program should return a complete madlib with each part of speech containing different words based on what the user said.

Current Behavior

However, if you create a template with two or more parts of speech the program returns a KeyError.

Possible Solution

I looked at the code and know exactly what is wrong. Basically, when the program runs through, the template, it gathers all the words in square brackets and puts them into a dictionary. Whenever it comes across a repeating word, it overwrites the original entry instead of creating a new one. This means that when the program needs words, it finds only one (the overwritten one). This is an easy fix, (make each dictionary key unique), but I just wanted to let everyone know.

Steps to Reproduce

  1. Make sure you have the latest version of the code on your computer.
  2. Place the attached file bakers_daughter.txt in the my_madlibs directory.
  3. Then run Madlib.py and set the file to bakers_daughter.txt
  4. Fill in everything that it asks for, and in the end, it will return an error.

Context (Environment)

This bug puts a large constraint on template making. In most madlibs, there are repeating parts of speech. Whenever somebody has more than one part of speech such as [noun] in the file and then runs the program, they get a KeyError and the only way to get around this would be to name each part of speech differently, such as [noun1] or [noun2] which is unrealistic.

I propose an easy fix, where the program will track repeating words and name their dictionary keys differently.

bakers_daughter.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.