#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Any way to skip to certain sections of a program?


    Hey guys! New to these forums and to programming in general. My group and I have come across a problem with our program. The programs purpose is to suggest certain Christmas presents based off of the users choice of either choosing 'yes' or 'no' to our specified questions. I've managed to create the program successfully but there is one BIG problem that i have come across and after hours and hours of searching, I have not yet found a solution for. For certain questions, if the user inputs 'no' then we want the program to by pass a certain question and move onto the following (Example: Question 2, do you like dogs? if 'yes' move onto question 3, if 'no' skip question 3 and move on to question 4). I am aware that there is no 'goto' function in python and I have been screwing around with different types of loops in attempts to skip over the questions that i'd like to dismiss based on the users input. I am NOT looking for anyone to DO the question for me, but i'd really appreciate a suggestion or any information that could point me in the right direction to resolving this issue. I apologize if this explanation was too lengthy/unstructured, i'm a bit frustrated at the moment! Thanks for any responses in advance!

    # When participating in multiple choice questions, we ask you to select numbers 1 through 6 rather than the word itself! Thank you
    print "welcome to the gift giver"

    giver=raw_input('what is your name: ')
    print ' '

    recipient=raw_input('what is your friends name?: ')
    print ' '

    ans01=raw_input('Question1: do you really want to get %s a gift? ' %recipient, )
    if ans01=='yes':
    print 'Well, then lets get started!'
    print ' '

    else:
    print 'maybe you should get him coal in that case!'
    print ' '

    ans02=raw_input('Question 2: Does %s like sports? ' %recipient, )
    if ans02=='yes': If Ans02=No, Skip to ans04
    print '%s enjoys sports!' %recipient
    print ' '
    else:
    print '%s does not enjoy sports!' %recipient
    print ' '

    ans03=raw_input('Question 3: Which of these sports does %s like? ' %recipient )
    print '1)soccer'
    print '2)basketball'
    print '3)tennis'
    print '4)rowing'
    print '5)baseball'
    print '6)football'
    choice=input('Answer= ')
    if choice==1:
    print 'You have chosen Soccer, here are some gifts related to the sport! Glow in the dark soccer ball, FIFA World Cup Soccer for Xbox360, Shin Gaurds, Soccer Jerseys, Red Bull Soccer Team Tickets,'
    print ' '
    elif choice==2:
    print 'You have chosen, Basketball, here are some gifts related to the sport! Basketball jersey, New York Nets Ticket, Glow in the dark Basket Ball, Basketball Shoes, Signed autograph by Jason Kidd'
    print ' '
    elif choice==3:
    print 'You have chosen, Tennis, here are some gifts related to the sport! Tennis shoes, Tennis Racquet, Ticket to the Webley Open at Madison Square Garden, Glow in the dark Tennis Ball, Signed Tennis Ball by Andy Rodrick'
    print ' '
    elif choice==4:
    print 'You have chosen, Rowing, here are some gifts related to the sport! Tickets to Princeton Rowing Team Match, Rutgers Crew Jersey, Rowing oar Rater, heart-rate Monitor, Rowing Shoes, Rutgers Crew Baseball Cap'
    print ' '
    elif choice==5:
    print 'You have chosen, Baseball, here are some gifts related to the sport! New York Yankee Tickets, Glow in the Dark Baseball, Baseball Cleats, Derek Jeter signed Yankee Jersey, Mets Baseball cap'
    print ' '
    elif choice==6:
    print 'You have chosen, Football, here are some gifts related to the sport! Glow in the Dark Nerf Football, New York Giants tickets, Ray Rice signed Rutgers Jersey, New York Giants Baseball Cap, Football keychain'
    print ' '

    ans04=raw_input('Question 4: Does %s like to cook? ' %recipient, )
    if ans04=='yes':
    print '%s does enjoy making a meal!' %recipient
    print ' '

    else:
    print '%s does not enjoy cooking apprently!' %recipient
    print ' '

    ans05=raw_input('Question 5: Does %s have a pet? ' %recipient, )
    if ans05=='yes':
    print '%s has a pet!' %recipient
    print ' '

    else:
    print '%s does not have a pet' %recipient
    print ' '

    ans06=raw_input('Question 6: What kind of pet does %s own? ' %recipient, )
    print '1)Dog'
    print '2)Cat'
    print '3)Bird'
    print '4)Rodent'
    print '5)Reptile'
    choice=input('Answer= ')
    if choice==1:
    print '%s owns a Dog, here are some Dog related gifts! Vitamins, Name Tags, Dog Food, Leash, Dog Clothing' %recipient
    print ' '
    elif choice==2:
    print '%s owns a Cat, here are some Cat related gifts! Vitamins, Name Tags, Cat food, Cat clothing, Cat Toys' %recipient
    print ' '
    elif choice==3:
    print '%s owns a Bird, here are some Bird related gifts! Vitamins, Bird Food, Bird Cage, Bird Toys, Name Tag' %recipient
    print ' '
    elif choice==4:
    print '%s owns a Rodent, here are some Rodent related gifts! Kibble, Vitamins, Name Tag, Rodent Clothing, Rodent Toys' %recipient
    print ' '
    elif choice==5:
    print '%s owns a Reptile, here are some Reptile related gifts! Reptile Food, Vitamins, Name Tag, Reptile Clothing, Reptile Toys' %recipient
    print ' '

    ans07=raw_input('Question 7: Does %s have a plain room? ' %recipient )
    if ans07=='yes':
    print 'Here are some gifts related to spicing %s room up! Radiohead Band Poster, Computer chair, iPhone Speakers, Light stand' %recipient
    print ' '

    else:
    print 'In that case, lets move on to the next question!'
    print ' '

    ans08=raw_input('Question 8: Does %s smell bad? ' %recipient, )
    if ans08=='yes':
    print 'In that case, lets take a look at some ways to make %s stench more tolerable!' %recipient
    print ' '

    else:
    print 'Well, we are happy %s does not have an oder problem!' %recipient
    print ' '

    ans09=raw_input('Question 9: Is %s a girl? ' %recipient, )
    if ans09=='yes':
    print 'In this case, here are some name brands for Female perfumes! Chanel, Burberry, Gucci, Chloe, Marc Jacobs'
    print ' '

    else:
    print 'In this case, here are some name brands for Male perfumes. Chanel, Burberry, Guccie, Giorgio, Armani, Versace'
    print ' '

    ans10=raw_input('Question 10: Does %s have a significant other? ' %recipient, )
    if ans10=='yes':
    print 'Here are some related gifts that we think %s significant other will appreciate!' %recipient
    print ' '

    else:
    print 'Here are a list of gifts that %s can enjoy by themselves! iPhone, iPad, Macbook Pro, $500 gift card, PLane Ticket to Paris' %recipient
    print ' '

    ans11=raw_input('Question 11: Does %s enjoy spending time with their significant other? ' %recipient, )
    if ans11=='yes':
    print 'Here is a list of items that %s and his or her significant other can enjoy together! Couples T-Shirt, $10000 gift card, 2 plane tickets to Paris, iPhone, Macbook Pro' %recipient
    print ' '

    else:
    print 'We are sorry to hear this, but here is a list of possible break up gifts that %s can give to his ex' %recipient
    print ' '
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    You could just do
    Code:
    ans1 = raw_input('Do you like dogs?')
    if ans1 == 'yes':
    	ans2 = raw_input('What kind of dog?')
    ans3 = raw_input('Do you like hamburgers?')
    if ans3 == 'yes':
    	ans4 = raw_input('What type of hamburgers?')
    Last edited by knutrainer; December 9th, 2012 at 11:53 PM. Reason: wrong format

IMN logo majestic logo threadwatch logo seochat tools logo