Forum Archive

Beginning High-Schooler needing help. Thanks.

ForeverHawk

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()
ForeverHawk

Also, I think I used tab correctly. It just did not show right up.

ccc

In Python we use def function_name(): to create a reusable block of code called a function. You did this correctly with space(). You had to put space() at the end of your program because defining a function does not run it's code. It's code is only run when you call 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 recognize Mars, MARS, mars and mArS as all being Mars.

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()
reefboy1

It's ok don't feel bad! I'm only in elementary school :-).

reefboy1

Oh yes, the "def" means define, and what is after that is the function or name of your function

ForeverHawk

Thanks for replies. I am very gratefully of you guys.
Bye.