Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0

    School project help!


    Hi im kinda new in Python and need some help for my second program writting in python.

    Well i have a AP Global project do and i wanna write a program to get extra credit.

    Well i want to learn how to write a program that ask the user a question. and then give a answer for that question. For example i want the program to ask a user to type a Vocabulary word and once the user do that the program will give that definition..

    Here wat i got to far..


    # Ap Talent Tenth Project

    print " Welcome"
    print " We are the talent Tenth the best out community have to offer"

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    I would like to that to be my title . Then

    raw_input("what is the term name User")
    if
    "wolrd war 2"

    print " Started in the end of the great depression back in the 1930's."

    ^^^^^^^^^^^^^^^^^^^^^^^^^
    I would like the program to keep on asking for new terms and name repeatly.



    how can i do this....can any one help me and show me how to write this program.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    17
    Rep Power
    0
    Why does this question look familar?

    see:
    http://forums.devshed.com/t210433/s.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0
    Originally Posted by ktpr
    Why does this question look familar?

    see:
    http://forums.devshed.com/t210433/s.html
    i visit the link but im still confuse it seems kinda messy for a beginnner...i read a guide on python but i help help

    how should i use the if statement and what go before it and after?
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Here's a small example (using a dictionary (not the one you open up and read as a book) would help).

    Code:
    print "Welcome!"
    answer1 = "a moving vehicle"
    answer2 = "a type of animal"
    question1 = raw_input("What is a car? ")
    if question1 == answer1:
         print "You've entered the correct answer!"
    else:
         print "You've entered an incorrect answer!"
    question2 = raw_input("What is a dog? ")
    if question2 == answer2:
         print "You've entered the correct answer!"
    else:
         print "You've entered an incorrect answer!"
    In order to have tons of questions and answers use a dictionary. I don't know much about them because I knew I wouldn't be using them. Python.org has a huge tutorial with that included in it. Check it out.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0
    Originally Posted by †Yegg†
    Here's a small example (using a dictionary (not the one you open up and read as a book) would help).

    Code:
    print "Welcome!"
    answer1 = "a moving vehicle"
    answer2 = "a type of animal"
    question1 = raw_input("What is a car? ")
    if question1 == answer1:
         print "You've entered the correct answer!"
    else:
         print "You've entered an incorrect answer!"
    question2 = raw_input("What is a dog? ")
    if question2 == answer2:
         print "You've entered the correct answer!"
    else:
         print "You've entered an incorrect answer!"
    In order to have tons of questions and answers use a dictionary. I don't know much about them because I knew I wouldn't be using them. Python.org has a huge tutorial with that included in it. Check it out.

    thsi helped thank you so much bro
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0
    i dont even know what is a dictionary...can someone give that info and how can i use it in my program
  12. #7
  13. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I myself do not know much about them because I knew I would never have a purpose (yet) to use a dictionary. A dictionary (in python) is used for storing larged amounts of data/information. Read the dictionary section of the tutorial at http://www.python.org.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0
    hi using the example iwrote this

    # Mr. Matthews AP project

    print "Welcome! we are the Talented Tenth, the best our community have to offer!"


    print " Please choose a Term below"
    print " albert einstein or jazz or coalition government"

    answer1 = "albert einstein"
    answer2 = "jazz"
    answer3 = "coalition goverment"
    answer4 = "yes"

    question1 = raw_input("What is your term?")
    if question1 == answer1:
    print "German-born physicist Albert Einstein offered startling new ideas on space,time,
    energy, and matter. In 1905, Einstein theorized that while the speed of light is
    constant, other things that seem constant, such as space and time, are not. Space and time
    can change when measured relative to an object moving near the speed of light which
    is 186,000 miles per second. Since relative motion is the key to Einstein's idea,
    it is called the **Theory of Relativity**"
    else:
    print "You mispelled the term, please try again **no capitals**"

    question2 = raw_input("What is your term?")
    if question2 == answer2:
    print "A new popular musical style called JAZZ emerged in the United States.
    It was developed by musicians
    mainly African Americans, in New Orleans, Memphis, and chicago.
    It swept the United States and Europe
    The lively, loose beat of jazz seemed to capture the new freedom of the age"
    else:
    print "You mispelled the term, please try again **no capitals**"

    question3 = raw_input("What is you term?")
    if question3 == answer3:
    print "When no single party won a majority, a coalition government,or temporary alliance
    of several parties"
    else:
    print "You mispelled the term, please try again **no capitals**?"

    question4 = raw_input("Are you finish?,type yes to exit")
    if question4 == answer4:
    print "Thankyou ,programmed writting by Group 6 member**Amado Tejada(Pichingo)**"




    but for some reason an error ..wat should i do
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    You should put spaces in. The lines after a colon must have an indent at the start.

    Code:
    if something:
        do_something
    else:
        do_something_else
    instead of

    Code:
    if something:
    do_something
    else:
    do_something_else
    Python uses the indentation to see where the 'block' of code starts and ends.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0
    Originally Posted by sfb
    You should put spaces in. The lines after a colon must have an indent at the start.

    Code:
    if something:
        do_something
    else:
        do_something_else
    instead of

    Code:
    if something:
    do_something
    else:
    do_something_else
    Python uses the indentation to see where the 'block' of code starts and ends.

    im confuse are u saying to put _ , but where next to print. or where
  20. #11
  21. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Just use the example I originally gave you. When going into another line if print, for example.

    print "The quick fox jumped over the lazy hound,"
    print "and then he tripped over a carrot."

    Doing this will be very simple. It's quick, easy, and doesn't involve much thinking.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    I dont even know what is a dictionary...can someone give that info and how can i use it in my program
    A dictionary is wonderfully useful. It's a way of storing things that map to something else, like in a real dictionary you have a word linked to a definition of what the word means or in a foreign dictionary you have a word linked to a translation of the word.

    Code:
    # English Dictionary
    >>> d = {}
    >>> d["camera"] = "A thing that takes pictures"
    >>> d["bark"] = "The noise a dog makes"
    >>> d["button"] = "Something you press"
    >>>
    >>> print d["button"]
    Something you press
    
    # English to German Dictionary
    >>> d = {}
    >>> d["monday"] = "Montag"
    >>> d["tuesday"] = "Dienstag"
    >>> d["wednesday"] = "Mittwoch"
    >>> d["thursday"] = "Donnerstag"
    >>> d["friday"] = "Freitag"
    >>> day = raw_input("Please enter a day")
    >>> if d.has_key(day): print d[day]

    You can use them in so many places once you realise how powerful and simple they are. They can also be initialised all at once, like:


    Code:
    LettersToNumbers = {'a':1, 'b':2, 'c':3', 'd':4, 'e':5}
    print LettersToNumbers['b']

    In order to have tons of questions and answers use a dictionary. I don't know much about them because I knew I wouldn't be using them.
    That's a shame because they are a really great feature of Python. Other languages have them and call them Hashtables or Maps and so on, but a lot of languages make them much harder to use, putting them in libraries that have to be imported, etc.
    With Python they are built in and really easy to use, and very powerful, you can be surprised where they are the easiest way to do something.
  24. #13
  25. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Ya I have noticed that Python simplifies many things unlike in other languages. I don't have much of a purpose for dictionaries as of right now, when the time comes I'll learn more about them.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    18
    Rep Power
    0
    I did what you said and did a new line for a very print. and i got this..

    # Mr. Matthews AP project

    print "Welcome! we are the Talented Tenth, the best our community have to offer!"


    print " Please choose a Term below"
    print " albert einstein or jazz or coalition government"

    answer1 = "albert einstein"
    answer2 = "jazz"
    answer3 = "coalition goverment"
    answer4 = "yes"

    question1 = raw_input("What is your term?")
    if question1 == answer1:

    print "German-born physicist Albert Einstein offered startling new ideas on space,time,"
    print "energy, and matter. In 1905, Einstein theorized that while the"
    print "speed of light is constant, other things that seem constant,"
    print "such as space and time, are not. Space and time can change when"
    print "measured relative to an object moving near the speed of light"
    print "which is 186,000 miles per second. Since relative motion is the"
    print "key to Einstein's idea, it is called the **Theory of"
    print "Relativity**"

    else:
    print "You mispelled the term, please try again **no capitals**"

    question2 = raw_input("What is your term?")
    if question2 == answer2:

    print "A new popular musical style called JAZZ emerged in the United States."
    print "It was developed by musicians"
    print "mainly African Americans, in New Orleans, Memphis, and chicago."
    print "It swept the United States and Europe"
    print "The lively, loose beat of jazz seemed to capture the new freedom of the age"

    else:
    print "You mispelled the term, please try again **no capitals**"

    question3 = raw_input("What is you term?")
    if question3 == answer3:

    print "When no single party won a majority, a coalition government,or temporary alliance"
    print "of several parties"

    else:
    print "You mispelled the term, please try again **no capitals**?"

    question4 = raw_input("Are you finish?,type yes to exit")
    if question4 == answer4:

    print "Thankyou ,programmed writting by Group 6 member**Amado Tejada(Pichingo)**"




    but i get a error that says "expected an indented block"

    what should i do??
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    "im confuse are u saying to put _ , but where next to print. or where"

    No, not underscores, just spaces. White space is a part of the Python language, it's not just for decoration. I bet your errors are "IndentationError: expected an indented block".

    When you have an IF statement, you need to indent the code it will run. When you have a WHILE loop, you need to indent the code that will be looping, and so on.

    Code:
    if 1 + 1 == 2:
    print "Yes, 1 plus 1 equals 2"
    -> IndentationError

    Code:
    if 1 + 1 == 2:
        print "Yes, 1 plus 1 equals 2"
    -> It will run.

    The code you posted had everything up against the far left of the screen, and it wont run like that.

    Any line that ends in : has to have indents on the next line until you've finished doing whatever it does.

    Check the difference between these, run them and see:

    Code:
    print "starting"
    
    if 1 + 1 == 5:
        print "that's not right"
    
    print "ending"
    and

    Code:
    print "starting"
    
    if 1 + 1 == 5:
        print "that's not right"
    
        print "ending"
    Last edited by sfb; December 14th, 2004 at 06:31 PM.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo