please wait

  • Ekta Singhania Mar-15-2019 06:16:08 AM ( 2 months ago )


    I'm creating this program in python that calculates you total cost according to how much you choose. so the program is pizza delivery, and the user has to choose their choice of pizza out of the menu. what I cant figure out is that how to tell python that whatever the users first,second and third choice is, the cost will be 3 dollars and the rest would be 5 dollars. what I mean in more dept would be that how do i tell python that the users 1st,2nd,3rd choice/input = $3.

    I tried writing: menu[0:3] = 3 but that just changes the food in the array/list.

  • Garry Buttler Mar-15-2019 06:17:58 AM ( 2 months ago )

    Try this function:

    def price(choice):
        if choice <= 3:
            cost = 3
            cost = 5
         return cost
    > 5
  • Sophia Chang Mar-15-2019 06:21:05 AM ( 2 months ago )

    You can create a counter variable for tracking inputs, increment it after taking each input. And then in the price section of your code, use an if statement to set price to 3 if counter < 4, else set price to 5.

    # Create counter variable
    counter = 0
    # Taking user input code here
    counter = counter + 1
    # Later when setting price in code
    if counter < 4:
        price = 3
        price = 5

Please login

Similar Discussion

Recommended For You