Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 14th, 2004, 04:48 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #2  
Old December 14th, 2004, 05:10 PM
ktpr ktpr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 17 ktpr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 47 sec
Reputation Power: 0
Why does this question look familar?

see:
http://forums.devshed.com/t210433/s.html

Reply With Quote
  #3  
Old December 14th, 2004, 05:14 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
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?

Reply With Quote
  #4  
Old December 14th, 2004, 05:29 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 43 sec
Reputation Power: 68
Send a message via AIM to 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.

Reply With Quote
  #5  
Old December 14th, 2004, 05:31 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #6  
Old December 14th, 2004, 05:33 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i dont even know what is a dictionary...can someone give that info and how can i use it in my program

Reply With Quote
  #7  
Old December 14th, 2004, 05:40 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 43 sec
Reputation Power: 68
Send a message via AIM to Yegg`
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.

Reply With Quote
  #8  
Old December 14th, 2004, 06:40 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #9  
Old December 14th, 2004, 06:59 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 9
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.

Reply With Quote
  #10  
Old December 14th, 2004, 07:01 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #11  
Old December 14th, 2004, 07:15 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 43 sec
Reputation Power: 68
Send a message via AIM to Yegg`
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.

Reply With Quote
  #12  
Old December 14th, 2004, 07:20 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 9
Quote:
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']



Quote:
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.

Reply With Quote
  #13  
Old December 14th, 2004, 07:24 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 43 sec
Reputation Power: 68
Send a message via AIM to Yegg`
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.

Reply With Quote
  #14  
Old December 14th, 2004, 07:25 PM
Pichingo2005 Pichingo2005 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 18 Pichingo2005 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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??

Reply With Quote
  #15  
Old December 14th, 2004, 07:26 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)