   Magic 8-ball - First game!
  Hiya! Well, I've finally got around to making my Magic 8-ball program, which is my first real game. It is written in Python 2.6.2, and I included the code. I am very satisfied with this program, even though it is simple. Also, I might have spelt "Confucious" wrong. [grin]import randomdice = ("Without a doubt", "It is certain", "Maybe","Yes", "All signs point to 23", "No", "Erm...no", "Try asking again","You should probably diffuse the bomb beneath your chair.", "Confucious says 'No'", "42")fish = 1while fish == 1:choice = raw_input("Type 'ask' to ask a question. Type 'info' for information. Type 'quit' to quit.\n")if choice == "ask":raw_input("Please enter your question:\n")roll = random.randint(0, 10)print dice[roll]raw_input()elif choice == "quit":fish = 0elif choice == "info":print "To use the Magic 8-Ball, type 'ask' (without the quotes) at the\nmain prompt. You will thenbe asked to enter your question,\n after which you will receive  the answer from the ball.\n\nCreated by The Supreme Dark Overlo-- Joe."raw_input()else:print "Error -- Try again\n"[Edited by - Pallando on August 4, 2009 5:21:54 PM]
  Any idea why the post is so strange? I didn't write the answers all on one line, nor the actual post, so why is it displaying it that way?;  Congrats on first program! One comment: It's "Confucius" according to Firefox's spellchecker.   ;  Congratulations on your first game! [smile]Your post looks elongated because you have some loong strings in your source. You can use multi-lined strings in Python to break up a lengthy string:import randomdice = ("Without a doubt",   "It is certain",   "Maybe",   "Yes",   "All signs point to 23",   "No",   "Erm...no",   "Try asking again",   "You should probably diffuse the bomb beneath your chair.",   "Confucious says 'No'",   "42")while True:    choice = raw_input("Type 'ask' to ask a question. "   "Type 'info' for information. "   "Type 'quit' to quit.\n").lower()   if choice == "ask":   raw_input("Please enter your question:\n")   roll = random.randrange(0, len(dice))   print dice[roll]    elif choice == "info":   print ("To use the Magic 8-Ball, type 'ask' (without the quotes) at the""\nmain prompt. You will then be asked to enter your question,""\nafter which you will receive  the answer from the ball.""\n\nCreated by The Supreme Dark Overlo-- Joe.")    elif choice == "quit":   break    else:   print "Error -- Try again\n"   raw_input()It's pretty tough to make improvements on what you have already, although note that I've added .lower() to make things case agnostic (i.e. you can now type in 'ASK' or 'aSk' and they'll be accepted). I've also removed the fish variable and achieved the same thing using while True and break to exit the loop. I have switched randint (which is deprecated I believe) for randrange (Note: randint(a, b) is identical to randrange(a, b+1)) and I used len find the length of the dice tuple, meaning you can add phrases to the tuple without having to modify any other code. A final modification was moving raw_input() out of the conditionals' bodies since I preferred it that way [smile]   ;  Isn't raw_input() discouraged because of something or another?  Not nit-picking, I just recall reading something of that effect.   ;Quote:Original post by EsysIsn't raw_input() discouraged because of something or another?  Not nit-picking, I just recall reading something of that effect.It wouldn't surprise me if you're thinking of input() which is considered unsafe as it is equivalent to eval(raw_input()). So if the user types an invalid expression, or worse they type some actual code, then things get more complicated.   ;Quote:Original post by dmatterCongratulations on your first game! [smile]Your post looks elongated because you have some loong strings in your source. You can use multi-lined strings in Python to break up a lengthy string:*** Source Snippet Removed ***It's pretty tough to make improvements on what you have already, although note that I've added .lower() to make things case agnostic (i.e. you can now type in 'ASK' or 'aSk' and they'll be accepted). I've also removed the fish variable and achieved the same thing using while True and break to exit the loop. I have switched randint (which is deprecated I believe) for randrange (Note: randint(a, b) is identical to randrange(a, b+1)) and I used len find the length of the dice tuple, meaning you can add phrases to the tuple without having to modify any other code. A final modification was moving raw_input() out of the conditionals' bodies since I preferred it that way [smile]Thanks for the pointers, very useful things to know! Much appreciated.   