![]() You could print the correct result immediately in response to a wrong reply. Results = ? ').lower()Īrgs = (results, tally, results, tally)įinally, people who take quizzes generally want to see the right answers. In the illustrationīelow, I started just by focusing on unifying the correct/incorrect tallies,īut that inspired other simplifications in the reporting of overall results. Simplify code (for example, by reducing if-else branching). Sometimes taking that approach will suggest further refactoring to ( correct and incorrect), consider whether you can unify them under a data Whenever you find yourself creating multiple closely related variables Make your scripts amenable to importing, easier debugging, andĪutomated testing should you ever need it. Stack the Countries makes learning about the world fun Watch the countries actually come to life in this colorful and dynamic game As you learn country ca. Nest the main() call under the conditional shown below. They do not require verbose instructions. The user understands the basics (computer prints state, user types capital), I recommend less chatty messages to users in interactive programs. The random library includes a choice() function, so you do not MAP IT: Tap the location of the selected state on the map. Sometimes a data-type suffix can disambiguate names, but STACK THE STATES: Build tall piles with states and try to reach the checkered line. (not sole) guide when picking variables: in most contexts, for example,Ĭapitals is a better name than stateDict states better than Opinions vary on this, but I recommend using natural language as the primary Then use Python's built-in string methods to capitalize geographic names for Level, and one advantage of putting them there is allowing the reader toįocus on the algorithm without the visual heaviness of a big data structure.ĭon't force your user to worry about capitalization: lowercase the data and You are on the right track in several respects - for example, putting allīehavior/actions inside of functions. Print("\nYou have",incorrect,"incorrect answers") Print("\nYou have",correct,"correct answers") MIN = 0Īns = input("\nEnter the capital of this state: ")Īgain = input("Type y to play again, anything else to stop: ") I took some of the advice into account that I got on my other posts and put the dictionary within the main function (I had it in its own function before), but was wondering if there was a more efficient way to do the while loop that is the basis of the game, as well as if me converting the dict to a list is an okay way to solve this problem. Stack the Countries on Windows Pc Developed By: Dan Russell-Pinson. At the end, it prints out both the amount of correct answers and amount of incorrect answers. This keeps going until the player decides to stop playing. state, asks for its capital, and keeps score. I have a program that gives the player a random U.S.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |