4 Replies - 862 Views - Last Post: 07 October 2012 - 01:46 AM Rate Topic: -----

#1 iaremarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-September 12

How to write an if/else condition within an if/else condition

Posted 05 October 2012 - 11:16 PM

Fortune Cookie Game: This program for a game a Chinese Take Out Restaurant (Lucky’s Chinese) uses when a customer buys 5 or more fortune cookies. Fortune Cookies cost $0.99 each.

Step 1: The program should start out by asking the user how many fortune cookies they would like to buy.
Input Validation: Do not let the user enter a number of cookies less than zero
If the user inputs less than 5 cookies print a message similar to the following:
Example (user purchased 4 cookies):
Sorry you do not qualify for the Lucky Chinese Fortune Game.
You only purchased 4 cookies.
Cost of Cookies: $3.96
For only $0.99 and one more cookie you qualify to play, would you like to buy more cookies? Enter Yes or No.

If the user enters No (make sure their input works regardless of whether the user enters an upper or lowercase response):
Display the following and end the program: Thank you for eating at Lucky’s Chinese!

If the user enters Yes (make sure their input works regardless of whether the user enters an upper or lowercase response): ask them how many more cookies they would like, and go back to step 1 above.
If the user inputs 5 or more cookies go to Step 2:
Step 2
If the user has input 5 or more cookies they are eligible for the game.
First, Display something similar to the following:
Example (for 5 fortune cookies purchased):
Welcome to the Lucky Chinese Fortune Game!
Each of your 5 fortune cookies will be opened and your fortune will be read.

This is my code for it
print("Welcome to Lucky Chinese Fortune Game")
print (" How many fortunes would you like to buy?") 
#get user input
x = input ()
valx = int (x)
#if the user didnt buy enough cookies use if/else condition
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? yes or no:") 
selection = "" 
while selection ! = "yes" and selection != "2"
selection = raw_input("select yes or no")
   if selection == "no" 
     print("Thank you for eating at Lucky's Chinese!") 
 else selection == 'yes':
    print("\nHow many more cookies would you like to buy?")
   #get user input
m = input ()
valm = int (m)

else: print ("Welcome to the Lucky Chinese Fortune Game!")


Is This A Good Question/Topic? 0
  • +

Replies To: How to write an if/else condition within an if/else condition

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2126
  • View blog
  • Posts: 3,257
  • Joined: 21-June 11

Re: How to write an if/else condition within an if/else condition

Posted 06 October 2012 - 02:16 AM

To answer the question in the title:

if condition1:
  ...
  if condition2:
    ...
  else:
    ...
else:
  ...



Your post's body doesn't really seem to contain a question, so I'm not sure how to help you there. Except to say that your code seems to contain some indentation errors and that I can't figure out which if the else on the last line is supposed to belong to.

This post has been edited by sepp2k: 06 October 2012 - 02:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 midknight51  Icon User is offline

  • New D.I.C Head

Reputation: 20
  • View blog
  • Posts: 47
  • Joined: 25-September 12

Re: How to write an if/else condition within an if/else condition

Posted 06 October 2012 - 02:20 AM

Hey there! I'm not sure exactly what you are asking, could you be a bit more clear?
Also, I do notice some indentation problems in your code as well as your variable 'cookies' does not seem to be defined unless you left out some of your code.

Edit: Ah, you beat me to it sepp2k!

This post has been edited by midknight51: 06 October 2012 - 02:20 AM

Was This Post Helpful? 0
  • +
  • -

#4 iaremarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-September 12

Re: How to write an if/else condition within an if/else condition

Posted 06 October 2012 - 07:02 PM

oops sorry
i meant to ask how would you be able to put an if/else condition within an if/else condition
i have been stuck on this part for a while didnt seem to work everytime i debug it
Was This Post Helpful? 0
  • +
  • -

#5 midknight51  Icon User is offline

  • New D.I.C Head

Reputation: 20
  • View blog
  • Posts: 47
  • Joined: 25-September 12

Re: How to write an if/else condition within an if/else condition

Posted 07 October 2012 - 01:46 AM

Well sepp2k explains exactly how to do it.
What errors are you getting? You need to give us all the information you can so we can help you.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1