10 Replies - 3719 Views - Last Post: 30 September 2012 - 11:22 PM Rate Topic: -----

#1 sillymonkey2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-September 12

How to write a program for fortune cookie game?

Posted 30 September 2012 - 09:43 PM

This is a homework question
Im a big noob im not sure if im doing this right.
this program includes if/elif/else

print("Welcome to Lucky Chinese Fortune Game")
print (" How many fortunes would you like to buy?") 
x = input ()
valx = int (x)
if (cookies > 5): 
   print ("\nSorry you do not qualify for the Lucky Chinese Fortune Game")
print (" you only purchased {} cookies.".format(valx)) 
print (" For only '$'0.99 and on more cookie you qualify to play,")
print ("Would you like to buy more cookies? Enter YES or NO")
if answer == 'NO': 
   elif:
     print("Thank you for eating at Lucky's Chinese!") 
if answer == 'YES': 
   else: 
     print"\nHow many more cookies would you like to buy?" 
       m = input ()
       valm = int (m)

print ("Welcome to the Lucky Chinese Fortune Game!")
def getfortune():
   
    fortuneRand = random.randrange(5) + 1 
    
    if fortuneRand == 1: 
      print "\nYou will receive a large some of money" 
    
    elif fortuneRand == 2:
       print "\nSomething you lost will soon turn up."
    
    elif fortuneRand == 3:
      print "\nYou will have bad luck for a week"
    
    elif fortuneRand == 4: 
       print "\nToday is your lucky day!" 
    
    elif fortuneRand ==5:
       print "\nYou will meet Mr. and Mrs. Right in 2 days!"
 if not the last cookie 
    elif print"\n press any key to continue to your next fortune cookie." 
    
    else print"\n This is your last cookie. Thank you for playing! Press any key to end the program" 
    
 if fortuneRand 4 
    else: 
    print ("It's your lucky day! congratulations!!!")
    
    print("pick a number between 1 and 4 to claim your prize: ")
        n= input ()
        valn= int (n)
   if(number == '1'):
      print("\n\tCongratulations: You won the big prize! A free dinner up to a '$'40 value! Thank you for playing!")
   elif(number == '2'): 
       print("\n\tCongratulations: You won the big prize! A free appetizer '('Up to a '$'15')'. Thank you for playing!")
   elif(number == '3'): 
       print("\n\tCongratulations: You won the big prize! Two free drinks with dinner. Thank you for playing!")
   elif(number == '4'):    
        print("\n\tCongratulations: You won the big prize! 5 free fortune cookies. Thank you for playing!")
   else:
      print ("\n\tYou have not made a valid selection")
      
   input("\n\nPress Enter to exit the program:)
   
main()


Is This A Good Question/Topic? 0
  • +

Replies To: How to write a program for fortune cookie game?

#2 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,063
  • Joined: 28-December 10

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 09:49 PM

What are you getting if it is run? Is it working as you expect it to?
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7996
  • View blog
  • Posts: 13,694
  • Joined: 19-March 11

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:01 PM

Try using a list to hold the cookie strings:
fortunes = ["fortune 1", "Some other clever fortune", "you will meet a tall, dark, handsome stranger... and kill him", "help, I'm being held prisoner in a fortune cookie factory!"]

# get a random number, use existing code for this

print fortunes [number-1]  # -1 to correct for zero-indexed list



Lists are more flexible and allow for shorter, more flexible code. For example, you could easily read in strings from a file and put them into a list - this is a lot harder with named variables.

This post has been edited by jon.kiparsky: 30 September 2012 - 10:02 PM

Was This Post Helpful? 0
  • +
  • -

#4 sillymonkey2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-September 12

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:01 PM

View PostfromTheSprawl, on 30 September 2012 - 09:49 PM, said:

What are you getting if it is run? Is it working as you expect it to?


it tells me that line 11 is wrong
Traceback (most recent call last):
  File "c:\Users\asus\fortune.py", line 11, in <module>
Syntax Error:    else:: c:\Users\asus\fortune.py, line 117


Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7996
  • View blog
  • Posts: 13,694
  • Joined: 19-March 11

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:06 PM

	if answer == 'NO':
	   elif:


If you really want to ignore the "NO" option, you need to insert a "pass" instruction so python knows you mean it.

	if answer == 'NO':
	   pass
	elif:

Was This Post Helpful? 0
  • +
  • -

#6 sillymonkey2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-September 12

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:24 PM

was able to fix some mistakes

but line 40 kind of stuck in a hard place
print("Welcome to Lucky Chinese Fortune Game")
print (" How many fortunes would you like to buy?") 
x = input ()
valx = int (x)
if (cookies > 5): 
   print ("\nSorry you do not qualify for the Lucky Chinese Fortune Game")
print (" you only purchased {} cookies.".format(valx)) 
print (" For only '$'0.99 and on more cookie you qualify to play,")
print ("Would you like to buy more cookies? Enter YES or NO")
if answer == 'NO': 
   pass
else:
     print("Thank you for eating at Lucky's Chinese!") 
if answer == 'YES':
   pass
else: 
     print("\nHow many more cookies would you like to buy?")
m = input ()
valm = int (m)

print ("Welcome to the Lucky Chinese Fortune Game!")
def getfortune():
   
    fortuneRand = random.randrange(5) + 1 
    
    if fortuneRand == 1: 
      print ("\nYou will receive a large some of money") 
    
    elif fortuneRand == 2:
       print ("\nSomething you lost will soon turn up.")
    
    elif fortuneRand == 3:
      print ("\nYou will have bad luck for a week.")
    
    elif fortuneRand == 4: 
       print ("\nToday is your lucky day!")
    
    elif fortuneRand ==5:
       print ("\nYou will meet Mr. and Mrs. Right in 2 days!")
 if not the last cookie:
 
    elif print("\n press any key to continue to your next fortune cookie.")
    
    else print"\n This is your last cookie. Thank you for playing!"
    "Press any key to end the program." 
    
 if fortuneRand 4 
    else: 
    print ("It's your lucky day! congratulations!!!")
    
    print("pick a number between 1 and 4 to claim your prize: ")
        n= input ()
        valn= int (n)
   if(number == '1'):
      print("\n\tCongratulations: You won the big prize! A free dinner up to" 
      "a '$'40 value! Thank you for playing!")
   elif(number == '2'): 
       print("\n\tCongratulations: You won the big prize!" 
             "A free appetizer '('Up to a '$'15')'. Thank you for playing!")
   elif(number == '3'): 
       print("\n\tCongratulations: You won the big prize!" 
             "Two free drinks with dinner. Thank you for playing!")
   elif(number == '4'):    
        print("\n\tCongratulations: You won the big prize!" 
              "5 free fortune cookies. Thank you for playing!")
   else:
      print ("\n\tYou have not made a valid selection.")
      
   input("\n\nPress Enter to exit the program:)
   
main()

Was This Post Helpful? 0
  • +
  • -

#7 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,063
  • Joined: 28-December 10

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:37 PM

I'm not sure this works on line 40:
if not the last cookie:

Add a variable called lastCookie and set it as False then when the program executes the conditions and knows it's the last cookie set lastCookie to true so you can change line 40 to this instead:
if not lastCookie:

Variable names don't allow for spaces, you know. ^^
Was This Post Helpful? 1
  • +
  • -

#8 sillymonkey2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-September 12

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:51 PM

View PostfromTheSprawl, on 30 September 2012 - 10:37 PM, said:

I'm not sure this works on line 40:
if not the last cookie:

Add a variable called lastCookie and set it as False then when the program executes the conditions and knows it's the last cookie set lastCookie to true so you can change line 40 to this instead:
if not lastCookie:

Variable names don't allow for spaces, you know. ^^


I did that it worked now line 43 wont work. its because of syntax error
print("Welcome to Lucky Chinese Fortune Game")
print (" How many fortunes would you like to buy?") 
x = input ()
valx = int (x)
if (cookies > 5): 
   print ("\nSorry you do not qualify for the Lucky Chinese Fortune Game")
print (" you only purchased {} cookies.".format(valx)) 
print (" For only '$'0.99 and on more cookie you qualify to play,")
print ("Would you like to buy more cookies? Enter YES or NO")
if answer == 'NO': 
   pass
else:
     print("Thank you for eating at Lucky's Chinese!") 
if answer == 'YES':
   pass
else: 
     print("\nHow many more cookies would you like to buy?")
m = input ()
valm = int (m)

print ("Welcome to the Lucky Chinese Fortune Game!")
def getfortune():
   
    fortuneRand = random.randrange(5) + 1 
    
    if fortuneRand == 1: 
      print ("\nYou will receive a large some of money") 
    
    elif fortuneRand == 2:
       print ("\nSomething you lost will soon turn up.")
    
    elif fortuneRand == 3:
      print ("\nYou will have bad luck for a week.")
    
    elif fortuneRand == 4: 
       print ("\nToday is your lucky day!")
    
    elif fortuneRand ==5:
       print ("\nYou will meet Mr. and Mrs. Right in 2 days!")
 if not the last cookie:
 
    elif print("\n press any key to continue to your next fortune cookie.")
    
    else print"\n This is your last cookie. Thank you for playing!"
    "Press any key to end the program." 
    
 if fortuneRand 4 
    else: 
    print ("It's your lucky day! congratulations!!!")
    
    print("pick a number between 1 and 4 to claim your prize: ")
        n= input ()
        valn= int (n)
   if(number == '1'):
      print("\n\tCongratulations: You won the big prize! A free dinner up to" 
      "a '$'40 value! Thank you for playing!")
   elif(number == '2'): 
       print("\n\tCongratulations: You won the big prize!" 
             "A free appetizer '('Up to a '$'15')'. Thank you for playing!")
   elif(number == '3'): 
       print("\n\tCongratulations: You won the big prize!" 
             "Two free drinks with dinner. Thank you for playing!")
   elif(number == '4'):    
        print("\n\tCongratulations: You won the big prize!" 
              "5 free fortune cookies. Thank you for playing!")
   else:
      print ("\n\tYou have not made a valid selection.")
      
   input("\n\nPress Enter to exit the program:)
   
main()


Traceback (most recent call last):
  File "c:\Users\asus\fortune.py", line 43, in <module>
builtins.Indentationerror: unindent does not match any outer indentation level (<wingdb_compile>, line 43)

Was This Post Helpful? 0
  • +
  • -

#9 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,063
  • Joined: 28-December 10

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 10:56 PM

I guess it's because your elif does not contain a condition on line 42.
Was This Post Helpful? 1
  • +
  • -

#10 sillymonkey2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-September 12

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 11:12 PM

View PostfromTheSprawl, on 30 September 2012 - 10:56 PM, said:

I guess it's because your elif does not contain a condition on line 42.

it came out different when i copied and pasted it
but it would be line 42 that im having problem with
Was This Post Helpful? 0
  • +
  • -

#11 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,063
  • Joined: 28-December 10

Re: How to write a program for fortune cookie game?

Posted 30 September 2012 - 11:22 PM

Yes, that is line 42 missing a condition. Else - ifs always contain a condition.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1