Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Beginning High-Schooler needing help. Thanks.
-
Sorry if I sound like an idiot, my English isn't very good and I am new to the Python. I just started using Python. I've been trying out some new things and wanted some help. This script isn't working, is there anyone adjustments need for it? What does the "def" mean and why do I need to end in the "space()" and I need to define space(). What does define do in the code. Thank you my friends. :)
def space(): print"You have arrived in Space!" print"Do you want to go to Mars or Jupiter?" answer == "raw_input("Type Mars/Jupiter then hit 'Enter') if answer == "Mars" print"Welcome to Mars" elif answer == "Jupiter" print"Welcome to Jupiter" else: print"You didn't pick either. Try again." space() space()
-
Also, I think I used tab correctly. It just did not show right up.
-
In Python we use
def function_name():
to create a reusable block of code called a function. You did this correctly withspace()
. You had to putspace()
at the end of your program because defining a function does not run it's code. It's code is only run when youcall
the function. Below I have shown how you can reuse (call)space()
three times in a row.Other things to watch out for are the placement of commas (:) and the difference between = and ==. I also added the string method
.title()
so that your program will recognizeMars
,MARS
,mars
andmArS
as all beingMars
.def space(): print("You have arrived in Space!") print("Do you want to go to Mars or Jupiter?") answer = raw_input("Type Mars/Jupiter then hit 'Enter': ").title() if answer == "Mars": print("Welcome to Mars") elif answer == "Jupiter": print("Welcome to Jupiter") else: print("You didn't pick either. Try again.") space() for i in xrange(3): space()
-
It's ok don't feel bad! I'm only in elementary school :-).
-
Oh yes, the "def" means define, and what is after that is the function or name of your function
-
Thanks for replies. I am very gratefully of you guys.
Bye.