#I know you're into D&D so you might like this. Using this layout I think you could make something fun if you tried. #I'm sure you know but just to cover it. A '#' symbol means that python will skip over this line of code and move on to the next. So you can make notes with it. #So we'll start out with a simple print command. Its going to print what I type to the console as long as they are in the quotes. print "You are standing in front of a store. Looking up you can read the sign through the rain. 'Avatar Comics and Games'. 'Shit, this place again.' you think to yourself." #This is where its going to get tricky. First we're going to ask the user a question using the print command. print "Do you open the doors and go inside?" #Now we're going to store the answer to the question in a variable. It can be called anything we want. I'm going to call it answer. Then we're going to use raw_input() to capture the users answer. answer = raw_input("Type yes or no?") #Now that we have the users info stored lets do something with it. WE'LL USE AN 'IF' STATMENT! if answer == 'yes': print "What a bad idea. This place smells like sadness. You spend your days playing the DC deck building game and learn nothing of the outside world!" elif answer == 'no': print "What a great idea! By not going inside your life has been saved. You'll never know the horrors that waited for you inside! Good call champ!" else: print "I have no idea what you are talking about. Fuck you." print "Game Over Loser." #You'll see that I did I few things there. First I used two equal signs. Do that. There is a reason. I'll tell you with my voice at sometime if you want to know. But do that in this case. Second I used a werid # statment called an 'elif'. Thats the combo of the world 'else' and 'if'. It's what you put between an if and an else. EXAMPLE! Say you wanted to only have two options. You would use an if and and else. But because we have # three options we use and 'elif' between the two. If you wanted to have four options you would use another elif before the else and so on. #Don't use this IDE. Use whatever you've been using. This one sucks. Just good for sharing code. #If you don't get programming right away just remember what this famous programmer said: 80% of coding is fixing bugs. The other 20% is writing bugs.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question