omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.

    Pythonista
    3
    6
    2580
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ForeverHawk
      ForeverHawk last edited by

      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()
      
      1 Reply Last reply Reply Quote 0
      • ForeverHawk
        ForeverHawk last edited by

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

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          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()
          
          1 Reply Last reply Reply Quote 0
          • reefboy1
            reefboy1 last edited by

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

            1 Reply Last reply Reply Quote 0
            • reefboy1
              reefboy1 last edited by

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

              1 Reply Last reply Reply Quote 0
              • ForeverHawk
                ForeverHawk last edited by

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors