1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Help to loop my probability badly coded program

Discussion in 'Software Development' started by S013, Oct 10, 2017.

Thread Status:
Not open for further replies.
  1. S013

    S013 Thread Starter

    Joined:
    Oct 10, 2017
    Messages:
    1
    import time
    print('Hello, what is your name? ')
    name = input('My name is ')
    name = name.title()
    print('Hello', name + " it's nice to meet you!")
    time.sleep(0.45)
    print('I am the Thanatos System')
    time.sleep(0.45)
    print('What would you like to do? ')


    option = input('Your options are Sport, Food ')

    if option == 'Sport':
    favsport = input('What is your favourite sport? ')
    sports = ['Gaming', 'Tennis', 'Hockey', 'Soccer', 'Basketball', 'Football', 'Golf', 'Baseball', 'Boxing', 'Cricket', 'Volleyball', 'Badminton', 'Surfing', 'Rugby', 'Netball', 'Rowing', 'Handball', 'Archery', 'Water Polo', 'Karate', 'Martial Arts', 'Horse Racing', 'Bowling', 'Polo', 'Table Tennis', 'Taekwondo', 'Fencing', 'Squash', 'Snowboarding', 'Ice Skating', 'Walking', 'Cycling', 'Running', 'Swimming', 'Diving']
    if favsport in sports:
    print('Oh, I like', favsport, 'too!')
    else:
    print("I don't know about that sport")


    if option == 'Food':
    favfood = input('What is your favourite food? ')
    food = ['Potato', 'Bread', 'Seafood', 'Pasta', 'Fry Rice', 'Salad', 'Cereals', 'Soup', 'Eggs', 'Pizza', 'Chicken', 'Turkey', 'Salmon', 'Roast Beef', 'Muffins', 'Broccole', 'Spinach', 'Peas', 'Carrot', 'Blueberries', 'Strawberries', 'Raspberries', 'Ice Cream', 'Yogurt', 'Sushi']
    if favfood in food:
    print('Yummy, I wish I could have',favfood, ' too!')
    else:
    print("Oh, I haven't heard of that food")


    option2 = input('What else would you like to do? ')
    if option2 in option:
    print('You have already selected that category. ')
    elif option2 == 'Food':
    favfood = input('What is your favourite food? ')
    food = ['Potato', 'Bread', 'Seafood', 'Pasta', 'Fry Rice', 'Salad', 'Cereals', 'Soup', 'Eggs', 'Pizza', 'Chicken', 'Turkey', 'Salmon', 'Roast Beef', 'Muffins', 'Broccole', 'Spinach', 'Peas', 'Carrot', 'Blueberries', 'Strawberries', 'Raspberries', 'Ice Cream', 'Yogurt', 'Sushi']
    if favfood in food:
    print('Yummy, I wish I could have',favfood, 'too!')
    else:
    print("Oh, I haven't heard of that food")


    elif option2 == 'Sport':
    favsport = input('What is your favourite sport? ')
    sports = ['Gaming', 'Tennis', 'Hockey', 'Soccer', 'Basketball', 'Football', 'Golf', 'Baseball', 'Boxing', 'Cricket', 'Volleyball', 'Badminton', 'Surfing', 'Rugby', 'Netball', 'Rowing', 'Handball', 'Archery', 'Water Polo', 'Karate', 'Martial Arts', 'Horse Racing', 'Bowling', 'Polo', 'Table Tennis', 'Taekwondo', 'Fencing', 'Squash', 'Snowboarding', 'Ice Skating', 'Walking', 'Cycling', 'Running', 'Swimming', 'Diving']
    if favsport in sports:
    print('Oh, I like', favsport, 'too!')
    else:
    print("I don't know about that sport")


    option3 = input('What else would you like to do? ')


    if option3 == 'Sport':
    favsport = input('What is your favourite sport? ')
    sports = ['Gaming', 'Tennis', 'Hockey', 'Soccer', 'Basketball', 'Football', 'Golf', 'Baseball', 'Boxing', 'Cricket', 'Volleyball', 'Badminton', 'Surfing', 'Rugby', 'Netball', 'Rowing', 'Handball', 'Archery', 'Water Polo', 'Karate', 'Martial Arts', 'Horse Racing', 'Bowling', 'Polo', 'Table Tennis', 'Taekwondo', 'Fencing', 'Squash', 'Snowboarding', 'Ice Skating', 'Walking', 'Cycling', 'Running', 'Swimming', 'Diving']
    if favsport in sports:
    print('Oh, I like', favsport, 'too!')
    else:
    print("I don't know about that sport")


    if option3 == 'Food':
    favfood = input('What is your favourite food? ')
    food = ['Bread', 'Seafood', 'Pasta', 'Fry Rice', 'Salad', 'Cereals', 'Soup', 'Eggs', 'Pizza', 'Chicken', 'Turkey', 'Salmon', 'Roast Beef', 'Muffins', 'Broccole', 'Spinach', 'Peas', 'Carrot', 'Blueberries', 'Strawberries', 'Raspberries', 'Ice Cream', 'Yogurt', 'Sushi']
    if favfood in food:
    print('Yummy, I wish I could have',favfood, 'too!')
    else:
    print("Oh, I haven't heard of that food")

    choice = input('Would you like to see something? ')
    if choice == 'Yes':
    from turtle import *
    print("Don't go over seven if you don't want it to take too long. ")
    neighbours = int(input('How many neighbours do you have? '))
    bgcolor('deepskyblue')
    penup()
    fillcolor('yellow')
    begin_fill()
    goto(100,200)
    forward(50)
    right(90)
    forward(50)
    right(90)
    forward(50)
    right(90)
    forward(50)
    end_fill()
    fillcolor('green')
    penup()
    goto(-200, -200)
    right(90)
    begin_fill()
    forward(400)
    left(90)
    forward(80)
    left(90)
    forward(400)
    end_fill()
    for amount in range(neighbours):
    pendown()
    fillcolor('red')
    begin_fill()
    backward(50)
    right(90)
    forward(50)
    left(90)
    forward(50)
    left(90)
    forward(50)
    end_fill()
    fillcolor('black')
    begin_fill()
    backward(50)
    left(150)
    forward(50)
    right(120)
    forward(50)
    right(120)
    forward(50)
    end_fill()
    fillcolor('ghostwhite')
    begin_fill()
    left(90)
    forward(50)
    left(90)
    forward(16)
    left(90)
    forward(25)
    right(90)
    forward(18)
    right(90)
    forward(25)
    end_fill()
    penup()
    left(90)
    forward(21)
    left(180)

    input('Press Enter to exit')

    ----------------------------------------------------------------------------------------------------------------
    Trying to loop the question:
    What would you like to do?

    The options are:
    Sport and Food

    or if you know how to skip the last option('option3') when they have already inputted sport and food in option and option2

    and the spacing is off when i submitted this feels bad have to attempt to work out the spaces sorry
     
  2. computingforus

    computingforus

    Joined:
    Nov 10, 2014
    Messages:
    11
    First Name:
    Jevan
    I see your program is in python and it uses the turtle module.

    Try this. I don't know why it's not using the full width of the screen in this post?

    Code:
    import time
    
    food = ['Potato', 'Bread', 'Seafood', 'Pasta', 'Fry Rice', 'Salad', 'Cereals', 'Soup', 'Eggs', 'Pizza', 'Chicken', 'Turkey', 'Salmon', 'Roast Beef', 'Muffins', 'Broccole', 'Spinach', 'Peas', 'Carrot', 'Blueberries', 'Strawberries', 'Raspberries', 'Ice Cream', 'Yogurt', 'Sushi']
    sports = ['Gaming', 'Tennis', 'Hockey', 'Soccer', 'Basketball', 'Football', 'Golf', 'Baseball', 'Boxing', 'Cricket', 'Volleyball', 'Badminton', 'Surfing', 'Rugby', 'Netball', 'Rowing', 'Handball', 'Archery', 'Water Polo', 'Karate', 'Martial Arts', 'Horse Racing', 'Bowling', 'Polo', 'Table Tennis', 'Taekwondo', 'Fencing', 'Squash', 'Snowboarding', 'Ice Skating', 'Walking', 'Cycling', 'Running', 'Swimming', 'Diving']
    
    def processSport():
     favsport = input('What is your favourite sport? ')
     if favsport in sports:
      print('Oh, I like', favsport, 'too!')
     else:
      print("I don't know about that sport")
    
    def processFood():
     favfood = input('What is your favourite food? ')
     if favfood in food:
      print('Yummy, I wish I could have',favfood, ' too!')
     else:
      print("Oh, I haven't heard of that food")
    
    def processOptions(option,allowSport,allowFood):
     if (option == 'Sport') and (allowSport==1): processSport()
     elif (option == 'Food') and (allowFood==1): processFood()
     elif (option != 'Food') and (option != 'Sport'): print('That is not a valid option. ')
     else: print('You have already selected that category. ')
    
    def activity(message, allowSport, allowFood):
     print(message)
     optionsMessage = 'Your options are '
     if allowSport==1 and allowFood==1 : optionsMessage = optionsMessage + "Sport, Food "
     if allowSport==1 and allowFood==0 : optionsMessage = optionsMessage + "Sport "
     if allowSport==0 and allowFood==1 : optionsMessage = optionsMessage + "Food "
     if allowSport==0 and allowFood==0 :
      print('You have already selected all categories. ');
      option = ""
     else:
      option = input(optionsMessage);
      processOptions(option,allowSport,allowFood)
     return option
    
    print('Hello, what is your name? ')
    name = input('My name is ')
    name = name.title()
    print('Hello', name + " it's nice to meet you!")
    time.sleep(0.45)
    print('I am the Thanatos System')
    time.sleep(0.45)
    allowSport=1
    allowFood=1
    option=activity('What would you like to do? ',allowSport,allowFood)
    if option=='Food': allowFood=0
    if option=='Sport': allowSport=0
    option=activity('What else would you like to do? ',allowSport,allowFood)
    if option=='Food': allowFood=0
    if option=='Sport': allowSport=0
    option=activity('What else would you like to do? ',allowSport,allowFood)
    if option=='Food': allowFood=0
    if option=='Sport': allowSport=0
    choice = input('Would you like to see something? ')
    if choice == 'Yes':
     from turtle import *
     print("Don't go over seven if you don't want it to take too long. ")
     neighbours = int(input('How many neighbours do you have? '))
     bgcolor('deepskyblue')
     penup()
     fillcolor('yellow')
     begin_fill()
     goto(100,200)
     forward(50)
     right(90)
     forward(50)
     right(90)
     forward(50)
     right(90)
     forward(50)
     end_fill()
     fillcolor('green')
     penup()
     goto(-200, -200)
     right(90)
     begin_fill()
     forward(400)
     left(90)
     forward(80)
     left(90)
     forward(400)
     end_fill()
     for amount in range(neighbours):
      pendown()
      fillcolor('red')
      begin_fill()
      backward(50)
      right(90)
      forward(50)
      left(90)
      forward(50)
      left(90)
      forward(50)
      end_fill()
      fillcolor('black')
      begin_fill()
      backward(50)
      left(150)
      forward(50)
      right(120)
      forward(50)
      right(120)
      forward(50)
      end_fill()
      fillcolor('ghostwhite')
      begin_fill()
      left(90)
      forward(50)
      left(90)
      forward(16)
      left(90)
      forward(25)
      right(90)
      forward(18)
      right(90)
      forward(25)
      end_fill()
      penup()
      left(90)
      forward(21)
      left(180)
    
    input('Press Enter to exit')
    
    
     
    Last edited: Oct 15, 2017
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Help loop probability
  1. MarkLopez912
    Replies:
    3
    Views:
    158
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1197658

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice