On Fri, Dec 13, 2013 at 5:10 AM, Sky blaze <skyblaze...@gmail.com> wrote: > Hi, I'm a newbie Python programmer. I was introduced to Python via the Hour > of Code, and after completing all three of Grok Learning's tutorials, I was > inspired to create a text-based RPG adventure. I composed this e-mail after > searching for a forum for Python, and this address showed up in one of the > results. > > Due to my inexperience with Python, I'm having trouble creating a code for > one of the things I wanted to do for the game. The game starts out on a > "title screen" with a message saying, "Type 'start' to begin!" I thought > it'd be amusing to have the message change after the player types something > other than "start" at least 10 times. I've attempted numerous times to code > this, but all of them have failed. Could you help me with the coding? It > should look something like this in the end: > >>Type "start" to begin! >>No >>Type "start" to begin! >>Maybe >>Type "start" to begin! >>Perhaps >>Type "start" to begin! >>Nope >>Type "start" to begin! >>Why? >>Type "start" to begin! >>Are you sure? >>Type "start" to begin! >>You can't tell me what to do. >>Type "start" to begin! >>I'll start if I want to. >>Type "start" to begin! >>End >>Y U NO TYPE "start"?! >>Woah >>Y U NO TYPE "start"?! >>Okay, okay, I'll type it! >>Y U NO TYPE "start"?! >>start > > Here's the code I currently have so far: > print("===INSTRUCTIONS===") > input(">> ") > print("When you see a \'>>\', hit Enter to advance the text.") > print("When you see a \'> \', type in a command.") > print("Commands are displayed in quotations.") > print("Type them exactly as how they appear in quotations.") > print("For example. Type \"hi\" to wave!") > print("You would type hi next to the \'> \' prompt.") > print("Now that the basics are out of the way, enjoy the game!") > input(">> ") > print("***SUPER GENERIC SHORT TEXT RPG ADVENTURE***") > start = False #This is the start screen check > print("Type \"start\" to begin.") #Command message to start the game > start_prompt = input("> ") #Command prompt to start the game
Assuming Python 3. If it’s python 2, do raw_input() instead. > while start != True: #Infinite loop that doesn't end until "start" is typed Most people tend to do “while not start:” in this case. The reverse would be “while start:” and this also applies to if’s. > if start_prompt == "start": > start = True #Continues from the title screen > else: > #This is where I'm stuck. I can loop it so it always returns the > command message when > #"start" isn't typed, but changing the message upon having that > occur at least 10 times is > #what's giving me trouble. You need to count it somewhere, and test it. With that, it becomes fairly obvious, but with a catch: a one-off error can be easily made. Have some code: print("***SUPER GENERIC SHORT TEXT RPG ADVENTURE***") start = False # This is the start screen check print("Type \"start\" to begin.") # Command message to start the game start_prompt = input("> ") # Command prompt to start the game attempts = 1 # Count the start attempts made. If you made it a zero, that would break your example. while not start: if start_prompt == "start": start = True else: attempts += 1 if attempts < 10: print("Type \"start\" to begin.") else: print("Y U NO TYPE \"start\"?!") start_prompt = input("> ") -- Chris “Kwpolska” Warrick <http://kwpolska.tk> PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor