Need help in python

How to random a word list

Page 1 of 1

12 Replies - 1696 Views - Last Post: 12 June 2009 - 03:38 PM Rate Topic: -----

#1 3liminat3r  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 22-May 09

Need help in python

Post icon  Posted 25 May 2009 - 03:06 PM

Im making little games using python, im in school and just passed this class but it just went over the basics i asume.
promblem 1. after the game plays, it wont return to menu instead it exits..
problem 2. In the yourAge(), and wish() funtion, is there a way i can randomize the output??
problem 3. I have downloaded pygames i cant get it to work..anyhelp on that would help as well.
def main():
	option = 0
	tries = 0
	getmonth = 0
	
	

	while option !=5:
		
		option = choice()
		
		if option == 1:
			yourAge()
			
			stop = raw_input('Press ENTER to continue.')
			return choice
			exit()
		elif option == 2:
			dog()
			stop = raw_input('Press ENTER to continue.')
			return choice
			exit()
		elif option == 3:
			main1()
			stop = raw_input('Press ENTER to continue.')
			return choice
		elif option == 4:
			random()
			return choice
			exit()
		elif option == 5:
		   exit() 

def choice():
	print "\n"*30
	print 'iii	iii	 ii	 ii	 ii iiiiii  ii	ii'
	print 'ii i  i ii	i  i	ii		ii	i ii	ii'
	print 'ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii'
	print 'ii	  ii  ii	ii  ii	 ii ii	i ii	ii'
	print 'ii	  ii ii	  ii iiiiii ii iiiiii	iiii   productionz version 1.0'
	print
	print '1: Fortune'
	print '2: Find out how old you are in dog years '
	print '3: Make a wish '
	print '4: Guess the number im thinking of.. '
	print '5: Exit'
	print
	option = input('What would you like to do today enter 1-5: ')
	return option

def yourAge():
	print "\n"*30
	print 'iii	iii	 ii	 ii	 ii iiiiii  ii	ii'
	print 'ii i  i ii	i  i	ii		ii	i ii	ii'
	print 'ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii'
	print 'ii	  ii  ii	ii  ii	 ii ii	i ii	ii'
	print 'ii	  ii ii	  ii iiiiii ii iiiiii	iiii   productionz version 1.0'
	print
	print '\tWelcome to the fortune teller'
	print
	name = raw_input('Enter your name! ')
	print
	age = input('Enter your age! ')
	print
	if age <= 5:
		print name,' Your to young for a furtune, come back in 3 years!!'
		
	elif age <= 10:
		print name,'Something, great is going to happen soon!!'
		
	elif age <= 13:
		print name,'Your at the age now where your going to'
		print 'start notice change in your life!! This will not be a bad change,'
		print 'but remember your family will be there for you.'
		
	elif age <= 15:
		print name,'You have taken intrest in a guy/girl. '
		print 'Dont be afraid to talk to him/her. They have been checking you out too.'
	elif age <= 17:
		print name,' You are getting older and wiser, now is the time to invest'
		print 'in something that you have wanted to in the past.'
	elif age <= 21:
		print name,'Your 5 lucky lotto numbers are 15, 2, 31, 17, 22!'
		print 'Use these number on the next 5 lotto tickets you buy.'
	   
	elif age <= 23:
		print name,'Beer is a good thing, loosen up, live life!! I see'
		print 'good things comming for you in the future.'
	elif age <= 25:
		print name,'People are starting to notice the things you do.'
		print 'You may have made a few mistakes but focus on the good!'
	elif age <= 27:
		print name,'Something, great is going to happen soon!!'
	elif age <= 30:
		print name,'Your going to die in 1 week!!'
	elif age <= 32:
		print name,'Every one needs to laugh. Go out and do something eventurous this weekend...'
	elif age <= 35:
		print name,'Things people dont know wont hurt them. So if they dont ask dont'
		print 'tell.'
		
	elif age <= 40:
		print name,'Lucky lotto numbers are 17, 1, 52, 20, 30!! Play these numbers'
		print ' for the next month....'
	elif age <= 43:
		print name,'People make mistakes. Dont get frustrated with life because'
		print 'things will get better for you.'
		return option
	elif age <= 50:
		print name,'Enjoy life retirement is comming up!!'
	elif age <= 60:
		print name,'Keep playing the lotto, The number you have been getting will hit soon!!'
	else:
		print ' Your either already dead or going to die!!!'
		stop = raw_input('Press ENTER to continue.')
		return
def dog():
	print "\n"*30
	print 'iii	iii	 ii	 ii	 ii iiiiii  ii	ii'
	print 'ii i  i ii	i  i	ii		ii	i ii	ii'
	print 'ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii'
	print 'ii	  ii  ii	ii  ii	 ii ii	i ii	ii'
	print 'ii	  ii ii	  ii iiiiii ii iiiiii	iiii   productionz version 1.0'
	print
	print'\tHow old are you in dog years???'
	print
	name = raw_input('Enter your name! ')
	print
	age = input('Enter your age! ')
	age = age * 7
	print
	print name,'is',age,'dog years old'
	return 
	


def main1():
	getmonth = 0
	while getmonth !=12:
		getmonth = wish()
		if getmonth == 1:
			January()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 2:
			February()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 3:
			March()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 4:
			April()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 5:
			May()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 6:
			June()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 7:
			July()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 8:
			August()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 9:
			September()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 10:
			October()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 11:
			November()
			stop = raw_input('Press ENTER to continue.')
			exit()
		elif getmonth == 12:
			December()
			stop = raw_input('Press ENTER to continue.')
			exit()
		

def wish():
	print "\n"*30
	print 'iii	iii	 ii	 ii	 ii iiiiii  ii	ii'
	print 'ii i  i ii	i  i	ii		ii	i ii	ii'
	print 'ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii'
	print 'ii	  ii  ii	ii  ii	 ii ii	i ii	ii'
	print 'ii	  ii ii	  ii iiiiii ii iiiiii	iiii   productionz version 1.0'
	print
	print 'If you wish for something it may come true in the near furture.'
	print 'If you think it wont then most likely it will not come true.'
	print
	name = raw_input('Enter your name! ')
	print "\n"*5
	wish = raw_input('Enter your wish! I wish:')
	print
	print '1: January'
	print '2: February '
	print '3: March '
	print '4: April '
	print '5: May'
	print '6: June'
	print '7: July'
	print '8: August'
	print '9: September'
	print '10:October'
	print '11:November'
	print '12:December'
	print
	getmonth = input('Enter 1-12 on the month you would like your wish to come true: ')
	return getmonth

def January():
	print
	print 'Your wish is looking good pick another month.'
def February():
	print
	print 'In the next couple of weeks mention it to a higher figure.'
def March():
	print
	print 'This month you should get your wish but dont be gready.'
def April():
	print
	print 'I think your pushing it, wish for something else on this month.'
def May():
	print
	print 'You have already been told this is an impossible wish.'
def June():
	print
	print 'If you think about it long enough your wish will come true.'
def July():
	print
	print 'Enjoy the fireworks this month, Your wish will come in January.'
def August():
	print
	print 'You have wished to many times try again later.'
def September():
	print
	print 'Wish again something for your family and pick another month.'
def October():
	print
	print 'October is a good month, Dont get spooked at the haunted houses.'
	print 'this year and your wish will come true.'
def November():
	print
	print 'In the next couple of weeks mention it to a higher figure.'
def December():
	print
	print 'Christmas is around the corner, make more wishies in this month.'

def random():
	
	import random
	print "\n"*30
	print 'iii	iii	 ii	 ii	 ii iiiiii  ii	ii'
	print 'ii i  i ii	i  i	ii		ii	i ii	ii'
	print 'ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii'
	print 'ii	  ii  ii	ii  ii	 ii ii	i ii	ii'
	print 'ii	  ii ii	  ii iiiiii ii iiiiii	iiii   productionz version 1.0'

	print "\tWelcome to 'Guess my number!:"
	print "\n"*1
	print "\nI'm thinking of a number between 1 and 100."
	print "Try to guess it in as few attempts as possible.\n"
	print 'You will only have 6 tries, so guess wisley'
	the_number = random.randrange(1,101)
	tries = 0
	while True:
		print
		guess = int(raw_input("Take a guess: "))
		tries += 1
		if guess > the_number:
			print "Lower..."
		elif guess < the_number:
			print "Higher..."
		else:
			print "You guessed it! The number was", the_number
			print "And it only took you", tries, "tries!\n"
			
			stop = raw_input('Press ENTER to continue.')
			return 
		if  tries == 6:
			print "You have made 6 attempts, game over."
			
			stop = raw_input('Press ENTER to continue.')
			return 
			


	

main()
	



	




Is This A Good Question/Topic? 0
  • +

Replies To: Need help in python

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Need help in python

Posted 25 May 2009 - 03:38 PM

Holy print statements, batman!

If you need to print something on multiple lines, you can easily do it using triple quotes:

print """
This is
a multi-line
statement.
"""



Chances are the reason your code isn't returning to the main menu is because you have a call to exit() after each choice - try taking those out of each option that isn't actually supposed to exit.

If you want to randomize your output, look into random.choice - it will choose a random item from a list. So you'd store all your fortunes into a list, and then do something like this:
fortunes = ["fortune 1", "fortune 2"]
random.choice(fortunes)



Here is the documentation on installing pygame - unfortunately, that's all I can give you.
Was This Post Helpful? 0
  • +
  • -

#3 3liminat3r  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 22-May 09

Re: Need help in python

Posted 26 May 2009 - 01:55 PM

Ok thanks for the print''' thing that will save alot of time.. Here is my code, im still not doing something right with the wish() function.. Here is my cokde

def main():
	option = 0
	tries = 0
	getmonth = 0
	
	

	while option !=5:
		
		option = choice()
		
		if option == 1:
			yourAge()
			
			stop = raw_input('Press ENTER to continue.')
			 
		  
		elif option == 2:
			dog()
			stop = raw_input('Press ENTER to continue.')
			 
			
		elif option == 3:
			wish()
			stop = raw_input('Press ENTER to continue.')
			
		elif option == 4:
			random()
			
		   
		elif option == 5:
		   exit() 

def choice():
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0
   
	1: Fortune
	2: Find out how old you are in dog years 
	3: Make a wish 
	4: Guess the number im thinking of.. 
	5: Exit'''
	
	option = input('What would you like to do today enter 1-5: ')
	return option

def yourAge():
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0ersion 1.0'''
		
	print '\tWelcome to the fortune teller'
	print
	name = raw_input('Enter your name! ')
	print
	age = input('Enter your age! ')
	print
	if age <= 5:
		print name,' Your to young for a furtune, come back in 3 years!!'
		
	elif age <= 10:
		print name,'Something, great is going to happen soon!!'
		
	elif age <= 13:
		print name,'Your at the age now where your going to'
		print 'start notice change in your life!! This will not be a bad change,'
		print 'but remember your family will be there for you.'
		
	elif age <= 15:
		print name,'You have taken intrest in a guy/girl. '
		print 'Dont be afraid to talk to him/her. They have been checking you out too.'
	elif age <= 17:
		print name,' You are getting older and wiser, now is the time to invest'
		print 'in something that you have wanted to in the past.'
	elif age <= 21:
		print name,'Your 5 lucky lotto numbers are 15, 2, 31, 17, 22!'
		print 'Use these number on the next 5 lotto tickets you buy.'
	   
	elif age <= 23:
		print name,'Beer is a good thing, loosen up, live life!! I see'
		print 'good things comming for you in the future.'
	elif age <= 25:
		print name,'People are starting to notice the things you do.'
		print 'You may have made a few mistakes but focus on the good!'
	elif age <= 27:
		print name,'Something, great is going to happen soon!!'
	elif age <= 30:
		print name,'Your going to die in 1 week!!'
	elif age <= 32:
		print name,'Every one needs to laugh. Go out and do something eventurous this weekend...'
	elif age <= 35:
		print name,'Things people dont know wont hurt them. So if they dont ask dont'
		print 'tell.'
		
	elif age <= 40:
		print name,'Lucky lotto numbers are 17, 1, 52, 20, 30!! Play these numbers'
		print ' for the next month....'
	elif age <= 43:
		print name,'People make mistakes. Dont get frustrated with life because'
		print 'things will get better for you.'
		return option
	elif age <= 50:
		print name,'Enjoy life retirement is comming up!!'
	elif age <= 60:
		print name,'Keep playing the lotto, The number you have been getting will hit soon!!'
	else:
		print ' Your either already dead or going to die!!!'
		stop = raw_input('Press ENTER to continue.')
		return option
def dog():
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0'''
	print
	print'\tHow old are you in dog years???'
	print
	name = raw_input('Enter your name! ')
	print
	age = input('Enter your age! ')
	age = age * 7
	print
	print name,'is',age,'dog years old'
	print
	stop = raw_input('Press ENTER to continue.')
	return  

def wish():
	import random
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0'''
	print
	print 'If you wish for something it may come true in the near furture.'
	print 'If you think it wont then most likely it will not come true.'
	print
	name = raw_input('Enter your name! ')
	print "\n"*5
	wish = raw_input('Enter your wish! I wish:')
	print
	print'''
	1: January
	2: February 
	3: March 
	4: April 
	5: May
	6: June
	7: July'
	8: August'
	9: September'
	10:October'
	11:November'
	12:December'''
	print
	random.choice = random.choice(r1, r2, r3, r4, r5)
	random.choice = input('Enter 1-12 on the month you would like your wish to come true: ')
	print random.choice(['r1', 'r2', 'r3', 'r4', 'r5'])
	r1 = 'Sorry, Your wish will is to extream..'
	r2 = 'Your wish is looking good.'
	r3 = 'Your trying to hard.'
	r4 = 'Hey! your wish is looking good.'
	r5 = 'Wow, Talk to someone about this.'
	


def random():
	
	import random
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0'''
	print
	print "\tWelcome to 'Guess my number!:"
	print '\n'*1
	print "\nI'm thinking of a number between 1 and 100."
	print "Try to guess it in as few attempts as possible.\n"
	print 'You will only have 6 tries, so guess wisley'
	the_number = random.randrange(1,101)
	tries = 0
	while True:
		print
		guess = int(raw_input("Take a guess: "))
		tries += 1
		if guess > the_number:
			print "Lower..."
		elif guess < the_number:
			print "Higher..."
		else:
			print "You guessed it! The number was", the_number
			print "And it only took you", tries, "tries!\n"
			
			stop = raw_input('Press ENTER to continue.')
			return 
		if  tries == 6:
			print "You have made 6 attempts, game over."
			
			stop = raw_input('Press ENTER to continue.')
			return option
			


	

main()
	



Was This Post Helpful? 0
  • +
  • -

#4 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 201
  • Joined: 21-April 09

Re: Need help in python

Posted 26 May 2009 - 03:00 PM

View Post3liminat3r, on 26 May, 2009 - 12:55 PM, said:

	random.choice = random.choice(r1, r2, r3, r4, r5)
	random.choice = input('Enter 1-12 on the month you would like your wish to come true: ')
	print random.choice(['r1', 'r2', 'r3', 'r4', 'r5'])
	r1 = 'Sorry, Your wish will is to extream..'
	r2 = 'Your wish is looking good.'
	r3 = 'Your trying to hard.'
	r4 = 'Hey! your wish is looking good.'
	r5 = 'Wow, Talk to someone about this.'



This is your problem, notice that you set the variable to "random.choice" and then later you call it, (), but a string or list can not be called.

Instead try something like this:

	choice = input('Enter 1-12 on the month you would like your wish to come true: ')
	print random.choice(['r1', 'r2', 'r3', 'r4', 'r5'])
	r1 = 'Sorry, Your wish will is to extream..'
	r2 = 'Your wish is looking good.'
	r3 = 'Your trying to hard.'
	r4 = 'Hey! your wish is looking good.'
	r5 = 'Wow, Talk to someone about this.'



Note that I'm not totally sure of your intention, so this may not be correct.

Also if your intenting to place r1, r2, r3, r4, r5 into a list, you should not type them as a string in the list. Remember that a list contains other data types. Here is an example in the interpreter:

>>> import random		# Make sure all imports are done before def
>>> a = "Something"
>>> b = "Something else"
>>> list = [a, b]			# list set to objects a, b
>>> index = random.randint(0, 1)  #random index
>>> list[index]
'Something'
>>> list = ["a", "b"]	   # list set to new string objects
>>> random.choice(list)
'b'


This post has been edited by code_m: 26 May 2009 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

#5 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Need help in python

Posted 26 May 2009 - 03:15 PM

A cleaner(in my opinion) way to do the same thing would be to store your strings into a list, and use random.choice on that - like so:
fortunes = [
"r1 goes here",
"r2 goes here",
"r3 goes here",
]
print random.choice(fortunes)



A quick test in the shell shows you that this works:
>>> fortunes = ["r1 goes here", "r2 goes here", "r3 goes here"]
>>> import random
>>> random.choice(fortunes)
'r3 goes here'
>>> random.choice(fortunes)
'r1 goes here'
>>> random.choice(fortunes)
'r3 goes here'
>>> random.choice(fortunes)
'r1 goes here'
>>> random.choice(fortunes)
'r1 goes here'
>>> random.choice(fortunes)
'r1 goes here'
>>> random.choice(fortunes)
'r3 goes here'
>>> random.choice(fortunes)
'r2 goes here'


Was This Post Helpful? 0
  • +
  • -

#6 3liminat3r  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 22-May 09

Re: Need help in python

Posted 26 May 2009 - 04:52 PM

Ok i tryed it this way and still cant get it to work.... The other way is a lil to complex for me right now, i dont understand all the stuff on how to set it up. Also the name=,wish=,month= is just for the look to seem like its collecting data. here is my code i tryed..
def wish():
	import random
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0'''
	print
	print 'If you wish for something it may come true in the near furture.'
	print 'If you think it wont then most likely it will not come true.'
	print
	name = raw_input('Enter your name! ')
	print "\n"*5
	wish = raw_input('Enter your wish! I wish:')
	print
	print'''
	1: January
	2: February 
	3: March 
	4: April 
	5: May
	6: June
	7: July
	8: August
	9: September
	10:October
	11:November
	12:December'''
	print
	month = input('Enter the month you want your wish: ')
	fortunes = ["You must likly will get your wish"," Your wish may come in a few months","Your wish wont come true",]
	print random.choice(fortunes)


Here is the out put:

Enter the month you want your wish: 3
Traceback (most recent call last):
File "C:\Documents and Settings\Owner.bribri\Desktop\Foutune teller.py", line 225, in <module>
main()
File "C:\Documents and Settings\Owner.bribri\Desktop\Foutune teller.py", line 24, in main
wish()
File "C:\Documents and Settings\Owner.bribri\Desktop\Foutune teller.py", line 177, in wish
print random.choice(fortunes)
TypeError: 'int' object is not callable
Was This Post Helpful? 0
  • +
  • -

#7 3liminat3r  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 22-May 09

Re: Need help in python

Posted 27 May 2009 - 02:11 PM

ok not forsure if i need the a= b= c= but it is working.... thanks for your help guys... here is my code...
def wish():
	import random
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0'''
	print
	print 'If you wish for something it may come true in the near furture.'
	print 'If you think it wont then most likely it will not come true.'
	print
	name = raw_input('Enter your name! ')
	print "\n"*5
	wish = raw_input('Enter your wish! I wish for:')
	print "\n"*30
	print'''
	1: January
	2: February 
	3: March 
	4: April 
	5: May
	6: June
	7: July
	8: August
	9: September
	10:October
	11:November
	12:December'''
	print
	month = input('Enter the month 1-12: ')
	a = "Your wish will come true in two weeks!"
	b = "Your wish is to exsrteam pick another month!"
	c = "Your wish will not come true!"
	list = [a, b, c]			# list set to objects a, b
	index = random.randint(0, 1)  #random index
	list[index]
	
	list = ["Your wish will come true in two weeks!",
			"Your wish is to exsrteam pick another month!",
			"Your wish will not come true!", "Your wishing to much try again later",
			"Ask and you shall get"]	   # list set to new string objects
	print random.choice(list)
	return list

Was This Post Helpful? 0
  • +
  • -

#8 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 201
  • Joined: 21-April 09

Re: Need help in python

Posted 27 May 2009 - 04:33 PM

Ok, just so you know, you've still have much to learn and I could nit-pick your code all day long, but I will suggest only the issue we have been working.

    month = input('Enter the month 1-12: ')
    a = "Your wish will come true in two weeks!"
    b = "Your wish is to exsrteam pick another month!"
    c = "Your wish will not come true!"
    list = [a, b, c]            # list set to objects a, b
    index = random.randint(0, 1)  #random index
    list[index]
    
    list = ["Your wish will come true in two weeks!",
            "Your wish is to exsrteam pick another month!",
            "Your wish will not come true!", "Your wishing to much try again later",
            "Ask and you shall get"]       # list set to new string objects
    print random.choice(list)
    return list



when I posted my example, I was showing that it could be done in more than one way (sorry, I'm not the most clear teacher). You should do one of the random-list syntaxs

Most Pythonic: (best for holding immutable data, such as strings inside a list)
>>> list = ["string here", "string there",
                 "string everywhere",
                 ]
>>> print random.choice(list)



"Insert syntax": (best for holding mutable data, such as lists inside a list)
>>> one = "one bottle"
>>> two = "two bottles"
>>> list = [one, two]
>>> print random.choice(list)



##BAD: (was done ONLY for example)
>>> list = [1, 2, 3]
>>> index = random.randint(0, 2)   # must know length or call len()
>>> print list[index]




Also you shouldn't have a function both print and return the result. rarely should you ever print within a function, usually only main(). For this function your final line should be return random.choice(list) and then inside main() you should write print wish()
Was This Post Helpful? 0
  • +
  • -

#9 Dio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-June 09

Re: Need help in python

Posted 06 June 2009 - 11:24 AM

This is not regarding your question but I noticed something that might help you. You have the 'Malibu' title showing up throughout your code. Why not make it into a function and call it whenever you need it?

def title():
    print 'iii    iii     ii     ii     ii iiiiii  ii    ii'
    print 'ii i  i ii    i  i    ii        ii    i ii    ii'
    print 'ii  ii  ii   iiiiii   ii     ii iiiiii  ii    ii'
    print 'ii      ii  ii    ii  ii     ii ii    i ii    ii'
    print 'ii      ii ii      ii iiiiii ii iiiiii    iiii   productionz version 1.0'


def some_function():
    title() #calling it like this helps you avoid copying/pasting that 
            #game title every time and makes your code shorter


Was This Post Helpful? 0
  • +
  • -

#10 3liminat3r  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 22-May 09

Re: Need help in python

Posted 08 June 2009 - 07:02 AM

nice! I didnt think of that.. Thanks all who have helped me in this.. This post can be closed now..
Was This Post Helpful? 0
  • +
  • -

#11 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 201
  • Joined: 21-April 09

Re: Need help in python

Posted 08 June 2009 - 10:52 AM

Not so fast there 3liminat3r, I still don't think you have a full understanding of the code your writing...

The last I saw of you code you had put both examples in your program, when one was "correct" and the other was a clearer presentation.
Was This Post Helpful? 0
  • +
  • -

#12 3liminat3r  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 22-May 09

Re: Need help in python

Posted 11 June 2009 - 01:36 PM

Here is the finished code, I changed somethings around.. In the randomized word list, I tryed takin the a= 'something' out but couldnt get the code to work. It is working like the way it is though.. I'm still going to work on this a lil bit but school just started back and im in c++ and html. So this is going to take up much of my time..
def main():
	option = 0
	tries = 0
	getmonth = 0
	
	

	while option !=5:
		title()		
		option = choice()
		
		if option == 1:
			title()
			yourAge()
			print
			stop = raw_input('Press ENTER to continue.')
			 
		  
		elif option == 2:
			title()
			dog()
			print
			stop = raw_input('Press ENTER to continue.')
			 
			
		elif option == 3:
			title()
			wish()
			print
			stop = raw_input('Press ENTER to continue.')
			
		elif option == 4:
			title()
			random()
			
		   
		elif option == 5:
		   exit() 
def title():
	print "\n"*30
	print '''
			 iii	iii	 ii	 ii	 ii iiiiii  ii	ii
			 ii i  i ii	i  i	ii		ii	i ii	ii
			 ii  ii  ii   iiiiii   ii	 ii iiiiii  ii	ii
			 ii	  ii  ii	ii  ii	 ii ii	i ii	ii
			 ii	  ii ii	  ii iiiiii ii iiiiii	iiii
			 productionz version 1.0'''
	return
	
def choice():
	print'''
				 1: 8-Ball
				 2: Find out how old you are in dog years 
				 3: Make a wish 
				 4: Guess the number im thinking of.. 
				 5: Exit'''
	print
	option = input('\tWhat would you like to do today enter 1-5: ')
	return option

def yourAge():
	import random
	
	print	
	print '\tAsk the Magic 8-ball!'
	print
	ask = raw_input('Enter your question! ')
	a = "message"
	b = "message1"
	c = "message2"
	list = [a, b, c]			# list set to objects a, b
	index = random.randint(0, 1)  #random index
	list[index]
	
	list = ["Yes","Outlook not so good", "Maybe", "No", "Ask again later!"
			"8-ball must be broken.."]
			
			
	print
	print random.choice(list)
	return list

def dog():
	
	print
	print'\tHow old are you in dog years???'
	print
	name = raw_input('Enter your name! ')
	print
	age = input('Enter your age! ')
	age = age * 7
	print
	print name,'is',age,'dog years old'
	return  

def wish():
	import random
	print
	print 'If you wish for something it may come true in the near furture.'
	print 'If you think it wont then most likely it will not come true.'
	print
	name = raw_input('Enter your name! ')
	print "\n"*5
	wish = raw_input('Enter your wish! I wish for:')
	print "\n"*30
	print'''
	1: January
	2: February 
	3: March 
	4: April 
	5: May
	6: June
	7: July
	8: August
	9: September
	10:October
	11:November
	12:December'''
	print
	month = input('Enter the month 1-12: ')
	print
	a = "List 1"
	b = "List 2"
	list = [a, b, ]			# list set to objects a, b
	index = random.randint(0, 1)  #random index
	list[index]
	
	list = ["your wish will come true in two weeks!",
			"your wish is to exstream pick another month!",
			"your wish will not come true!", "your wishing to much try again later",
			"Ask and you shall get", "you cant always get what you want!!"]	   # list set to new string objects
	print 
	print name, ',', random.choice(list)
	return list
	


def random():
	
	import random
	print
	print "\tWelcome to 'Guess my number!:"
	print '\n'*1
	print "\nI'm thinking of a number between 1 and 100."
	print "Try to guess it in as few attempts as possible.\n"
	print 'You will only have 5 tries, so guess wisley'
	the_number = random.randrange(1,101)
	tries = 0
	while True:
		print
		guess = int(raw_input("Take a guess: "))
		tries += 1
		if guess > the_number:
			print "Lower..."
		elif guess < the_number:
			print "Higher..."
		else:
			print
			print "You guessed it! The number was", the_number
			print "And it only took you", tries, "tries!\n"
			
			stop = raw_input('Press ENTER to continue.')
			return 
		if  tries == 5:
			print
			print "You have made 5 attempts."
			print "The number was: ", the_number
			print'''
ggggg	 g	ggg  ggg ggggg	oooooo oo	   oo  ooooo ooooo
gg	   g g   gg gg gg gg	   oo  oo   oo	oo   oo	oo   o
gg  gg  ggggg  gg	gg ggg	  oo  oo	oo oo	 ooo   oo oo
gggggg gg   gg gg	gg gggggg   oooooo	  oo	  ooooo oo	o'''
			print
			
			stop = raw_input('Press ENTER to continue.')
			return
		
			
			


	

main()
	



	




Much thanks to everyone.. I'm sure i will need help in the other languages that i will be taking and hope for the same responses..
Was This Post Helpful? 0
  • +
  • -

#13 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 201
  • Joined: 21-April 09

Re: Need help in python

Posted 12 June 2009 - 03:38 PM

here's what you have:
    a = "List 1"
    b = "List 2"
    list = [a, b, ]            # list set to objects a, b
    index = random.randint(0, 1)  #random index
    list[index]
   
    list = ["your wish will come true in two weeks!",
            "your wish is to exstream pick another month!",
            "your wish will not come true!", "your wishing to much try again later",
            "Ask and you shall get", "you cant always get what you want!!"]       # list set to new string objects
    print
    print name, ',', random.choice(list)
    return list


the reason yours looks more messy is that you have an unnessary list within your code

and, here's what it needs to be:
    lamp = ["your wish will come true in two weeks!",
            "your wish is to exstream pick another month!",
            "your wish will not come true!", "your wishing to much try again later",
            "Ask and you shall get", "you cant always get what you want!!"]
    print "\n", name, ',', random.choice(lamp)


again, in the future you should return your variables, and then call to you fuction and print in main() or some other function(s) called by main(). I also noticed that you don't understand the use of a # (hash), this is use for commenting in code, a note for other programmers (and yourself!) but is never read by a compiler or interpreter). Note that I also change the name of the list, this is because list is a reserved name, in C++ you'll learn that you should never use a reserved name because you are then reimplamenting that name.

for example, try this:
>>> a = ["this", "is", "a", "list"]
>>> b = list() # equivalent to b = []
>>> list = a
>>> b = list()


You'll find that this causes an error, since the name list is no longer callable.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1