If statement only printing else










0















def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')


I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.










share|improve this question

















  • 1





    Possible duplicate of How can I read inputs as integers?

    – tripleee
    Nov 15 '18 at 4:59






  • 1





    @tripleee: The dupe you're suggesting doesn't cover the comparison to a range value, but you're about halfway there.

    – Makoto
    Nov 15 '18 at 5:00











  • @Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.

    – Emil Vatai
    Nov 15 '18 at 5:10
















0















def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')


I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.










share|improve this question

















  • 1





    Possible duplicate of How can I read inputs as integers?

    – tripleee
    Nov 15 '18 at 4:59






  • 1





    @tripleee: The dupe you're suggesting doesn't cover the comparison to a range value, but you're about halfway there.

    – Makoto
    Nov 15 '18 at 5:00











  • @Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.

    – Emil Vatai
    Nov 15 '18 at 5:10














0












0








0








def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')


I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.










share|improve this question














def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')


I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.







python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 4:55









WalkingLickWalkingLick

31




31







  • 1





    Possible duplicate of How can I read inputs as integers?

    – tripleee
    Nov 15 '18 at 4:59






  • 1





    @tripleee: The dupe you're suggesting doesn't cover the comparison to a range value, but you're about halfway there.

    – Makoto
    Nov 15 '18 at 5:00











  • @Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.

    – Emil Vatai
    Nov 15 '18 at 5:10













  • 1





    Possible duplicate of How can I read inputs as integers?

    – tripleee
    Nov 15 '18 at 4:59






  • 1





    @tripleee: The dupe you're suggesting doesn't cover the comparison to a range value, but you're about halfway there.

    – Makoto
    Nov 15 '18 at 5:00











  • @Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.

    – Emil Vatai
    Nov 15 '18 at 5:10








1




1





Possible duplicate of How can I read inputs as integers?

– tripleee
Nov 15 '18 at 4:59





Possible duplicate of How can I read inputs as integers?

– tripleee
Nov 15 '18 at 4:59




1




1





@tripleee: The dupe you're suggesting doesn't cover the comparison to a range value, but you're about halfway there.

– Makoto
Nov 15 '18 at 5:00





@tripleee: The dupe you're suggesting doesn't cover the comparison to a range value, but you're about halfway there.

– Makoto
Nov 15 '18 at 5:00













@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.

– Emil Vatai
Nov 15 '18 at 5:10






@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.

– Emil Vatai
Nov 15 '18 at 5:10













7 Answers
7






active

oldest

votes


















0














1.The range function in python3 returns an iteration type.



2.The input function in python3 returns a string and should be converted to an integer.
Try this:



amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')





share|improve this answer























  • Thank you, this has solved the issue for me.

    – WalkingLick
    Nov 15 '18 at 5:12


















2














You want



if amount in range(1,7):


rather than what you currently have,



if amount == range(1,7):


It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7) as a function that returns a list of numbers in that range. e.g.



range(1,7) ~~ [1, 2, 3, 4, 5, 6]


If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.




[edit]: As one of the other answers pointed out, you might also want to cast the result of your input() to an int - as input() generally returns a string.






share|improve this answer




















  • 1





    amount isn't an int, though. You're close.

    – Makoto
    Nov 15 '18 at 5:00











  • def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

    – WalkingLick
    Nov 15 '18 at 5:09











  • You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

    – Green Cloak Guy
    Nov 15 '18 at 5:15











  • I understand now, thank you for the help.

    – WalkingLick
    Nov 15 '18 at 5:18


















0














Try this code use in for ==



def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')





share|improve this answer






























    0














    You have to convert the input() from a string into an integer, otherwise you will always run the else statement. You can do that with int(), but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.






    share|improve this answer






























      0














      I have made some changes to your code. I believe this is what you are looking for.



      def quantity():
      global amount
      amount = int(input('How many tickets are you looking for? '))
      if amount in range(1,7):
      print('You have selected tickets '.format(amount))
      elif amount ==0 :
      print('You have selected 0 tickets')
      else:
      print('Please choose an amount between 0-6')





      share|improve this answer






























        0














        Instead of using if amount == range(1,7): use if amount in range(1,7):



        This is the modified code that you should use:



        def quantity():
        global amount
        amount = input('How many tickets are you looking for? ')
        if amount in range(1,7):
        print('You have selected tickets '.format(amount))
        elif amount == (0):
        print('You have selected 0 tickets')
        else:
        print('Please choose an amount between 0-6')





        share|improve this answer






























          -1














          input returns a string, so I guess you should be doing amount = int(input('...')).






          share|improve this answer























          • Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

            – Emil Vatai
            Nov 15 '18 at 5:04











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312657%2fif-statement-only-printing-else%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          7 Answers
          7






          active

          oldest

          votes








          7 Answers
          7






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          1.The range function in python3 returns an iteration type.



          2.The input function in python3 returns a string and should be converted to an integer.
          Try this:



          amount = int(input('How many tickets are you looking for? '))
          if amount in range(1,7):
          print('You have selected tickets '.format(amount))
          elif amount == (0):
          print('You have selected 0 tickets')
          else:
          print('Please choose an amount between 0-6')





          share|improve this answer























          • Thank you, this has solved the issue for me.

            – WalkingLick
            Nov 15 '18 at 5:12















          0














          1.The range function in python3 returns an iteration type.



          2.The input function in python3 returns a string and should be converted to an integer.
          Try this:



          amount = int(input('How many tickets are you looking for? '))
          if amount in range(1,7):
          print('You have selected tickets '.format(amount))
          elif amount == (0):
          print('You have selected 0 tickets')
          else:
          print('Please choose an amount between 0-6')





          share|improve this answer























          • Thank you, this has solved the issue for me.

            – WalkingLick
            Nov 15 '18 at 5:12













          0












          0








          0







          1.The range function in python3 returns an iteration type.



          2.The input function in python3 returns a string and should be converted to an integer.
          Try this:



          amount = int(input('How many tickets are you looking for? '))
          if amount in range(1,7):
          print('You have selected tickets '.format(amount))
          elif amount == (0):
          print('You have selected 0 tickets')
          else:
          print('Please choose an amount between 0-6')





          share|improve this answer













          1.The range function in python3 returns an iteration type.



          2.The input function in python3 returns a string and should be converted to an integer.
          Try this:



          amount = int(input('How many tickets are you looking for? '))
          if amount in range(1,7):
          print('You have selected tickets '.format(amount))
          elif amount == (0):
          print('You have selected 0 tickets')
          else:
          print('Please choose an amount between 0-6')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 5:07









          myhaspldeepmyhaspldeep

          16017




          16017












          • Thank you, this has solved the issue for me.

            – WalkingLick
            Nov 15 '18 at 5:12

















          • Thank you, this has solved the issue for me.

            – WalkingLick
            Nov 15 '18 at 5:12
















          Thank you, this has solved the issue for me.

          – WalkingLick
          Nov 15 '18 at 5:12





          Thank you, this has solved the issue for me.

          – WalkingLick
          Nov 15 '18 at 5:12













          2














          You want



          if amount in range(1,7):


          rather than what you currently have,



          if amount == range(1,7):


          It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7) as a function that returns a list of numbers in that range. e.g.



          range(1,7) ~~ [1, 2, 3, 4, 5, 6]


          If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.




          [edit]: As one of the other answers pointed out, you might also want to cast the result of your input() to an int - as input() generally returns a string.






          share|improve this answer




















          • 1





            amount isn't an int, though. You're close.

            – Makoto
            Nov 15 '18 at 5:00











          • def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

            – WalkingLick
            Nov 15 '18 at 5:09











          • You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

            – Green Cloak Guy
            Nov 15 '18 at 5:15











          • I understand now, thank you for the help.

            – WalkingLick
            Nov 15 '18 at 5:18















          2














          You want



          if amount in range(1,7):


          rather than what you currently have,



          if amount == range(1,7):


          It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7) as a function that returns a list of numbers in that range. e.g.



          range(1,7) ~~ [1, 2, 3, 4, 5, 6]


          If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.




          [edit]: As one of the other answers pointed out, you might also want to cast the result of your input() to an int - as input() generally returns a string.






          share|improve this answer




















          • 1





            amount isn't an int, though. You're close.

            – Makoto
            Nov 15 '18 at 5:00











          • def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

            – WalkingLick
            Nov 15 '18 at 5:09











          • You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

            – Green Cloak Guy
            Nov 15 '18 at 5:15











          • I understand now, thank you for the help.

            – WalkingLick
            Nov 15 '18 at 5:18













          2












          2








          2







          You want



          if amount in range(1,7):


          rather than what you currently have,



          if amount == range(1,7):


          It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7) as a function that returns a list of numbers in that range. e.g.



          range(1,7) ~~ [1, 2, 3, 4, 5, 6]


          If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.




          [edit]: As one of the other answers pointed out, you might also want to cast the result of your input() to an int - as input() generally returns a string.






          share|improve this answer















          You want



          if amount in range(1,7):


          rather than what you currently have,



          if amount == range(1,7):


          It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7) as a function that returns a list of numbers in that range. e.g.



          range(1,7) ~~ [1, 2, 3, 4, 5, 6]


          If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.




          [edit]: As one of the other answers pointed out, you might also want to cast the result of your input() to an int - as input() generally returns a string.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 5:01

























          answered Nov 15 '18 at 4:59









          Green Cloak GuyGreen Cloak Guy

          3,2651721




          3,2651721







          • 1





            amount isn't an int, though. You're close.

            – Makoto
            Nov 15 '18 at 5:00











          • def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

            – WalkingLick
            Nov 15 '18 at 5:09











          • You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

            – Green Cloak Guy
            Nov 15 '18 at 5:15











          • I understand now, thank you for the help.

            – WalkingLick
            Nov 15 '18 at 5:18












          • 1





            amount isn't an int, though. You're close.

            – Makoto
            Nov 15 '18 at 5:00











          • def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

            – WalkingLick
            Nov 15 '18 at 5:09











          • You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

            – Green Cloak Guy
            Nov 15 '18 at 5:15











          • I understand now, thank you for the help.

            – WalkingLick
            Nov 15 '18 at 5:18







          1




          1





          amount isn't an int, though. You're close.

          – Makoto
          Nov 15 '18 at 5:00





          amount isn't an int, though. You're close.

          – Makoto
          Nov 15 '18 at 5:00













          def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

          – WalkingLick
          Nov 15 '18 at 5:09





          def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount) So I added the if ... in and turned amount into an integer but still receive only the else part.

          – WalkingLick
          Nov 15 '18 at 5:09













          You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

          – Green Cloak Guy
          Nov 15 '18 at 5:15





          You need to put amount = int(amount) before you do the if condition, not after. You could even wrap the input() statement in an int() call

          – Green Cloak Guy
          Nov 15 '18 at 5:15













          I understand now, thank you for the help.

          – WalkingLick
          Nov 15 '18 at 5:18





          I understand now, thank you for the help.

          – WalkingLick
          Nov 15 '18 at 5:18











          0














          Try this code use in for ==



          def quantity():
          global amount
          amount = input('How many tickets are you looking for? ')
          if amount in range(1,7):
          print('You have selected tickets '.format(amount))
          elif amount == (0):
          print('You have selected 0 tickets')
          else:
          print('Please choose an amount between 0-6')





          share|improve this answer



























            0














            Try this code use in for ==



            def quantity():
            global amount
            amount = input('How many tickets are you looking for? ')
            if amount in range(1,7):
            print('You have selected tickets '.format(amount))
            elif amount == (0):
            print('You have selected 0 tickets')
            else:
            print('Please choose an amount between 0-6')





            share|improve this answer

























              0












              0








              0







              Try this code use in for ==



              def quantity():
              global amount
              amount = input('How many tickets are you looking for? ')
              if amount in range(1,7):
              print('You have selected tickets '.format(amount))
              elif amount == (0):
              print('You have selected 0 tickets')
              else:
              print('Please choose an amount between 0-6')





              share|improve this answer













              Try this code use in for ==



              def quantity():
              global amount
              amount = input('How many tickets are you looking for? ')
              if amount in range(1,7):
              print('You have selected tickets '.format(amount))
              elif amount == (0):
              print('You have selected 0 tickets')
              else:
              print('Please choose an amount between 0-6')






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 15 '18 at 4:58









              vishalkvishalk

              15117




              15117





















                  0














                  You have to convert the input() from a string into an integer, otherwise you will always run the else statement. You can do that with int(), but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.






                  share|improve this answer



























                    0














                    You have to convert the input() from a string into an integer, otherwise you will always run the else statement. You can do that with int(), but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.






                    share|improve this answer

























                      0












                      0








                      0







                      You have to convert the input() from a string into an integer, otherwise you will always run the else statement. You can do that with int(), but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.






                      share|improve this answer













                      You have to convert the input() from a string into an integer, otherwise you will always run the else statement. You can do that with int(), but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 15 '18 at 4:59









                      rushinstuffinrushinstuffin

                      785




                      785





















                          0














                          I have made some changes to your code. I believe this is what you are looking for.



                          def quantity():
                          global amount
                          amount = int(input('How many tickets are you looking for? '))
                          if amount in range(1,7):
                          print('You have selected tickets '.format(amount))
                          elif amount ==0 :
                          print('You have selected 0 tickets')
                          else:
                          print('Please choose an amount between 0-6')





                          share|improve this answer



























                            0














                            I have made some changes to your code. I believe this is what you are looking for.



                            def quantity():
                            global amount
                            amount = int(input('How many tickets are you looking for? '))
                            if amount in range(1,7):
                            print('You have selected tickets '.format(amount))
                            elif amount ==0 :
                            print('You have selected 0 tickets')
                            else:
                            print('Please choose an amount between 0-6')





                            share|improve this answer

























                              0












                              0








                              0







                              I have made some changes to your code. I believe this is what you are looking for.



                              def quantity():
                              global amount
                              amount = int(input('How many tickets are you looking for? '))
                              if amount in range(1,7):
                              print('You have selected tickets '.format(amount))
                              elif amount ==0 :
                              print('You have selected 0 tickets')
                              else:
                              print('Please choose an amount between 0-6')





                              share|improve this answer













                              I have made some changes to your code. I believe this is what you are looking for.



                              def quantity():
                              global amount
                              amount = int(input('How many tickets are you looking for? '))
                              if amount in range(1,7):
                              print('You have selected tickets '.format(amount))
                              elif amount ==0 :
                              print('You have selected 0 tickets')
                              else:
                              print('Please choose an amount between 0-6')






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 15 '18 at 5:03









                              NishilNishil

                              22518




                              22518





















                                  0














                                  Instead of using if amount == range(1,7): use if amount in range(1,7):



                                  This is the modified code that you should use:



                                  def quantity():
                                  global amount
                                  amount = input('How many tickets are you looking for? ')
                                  if amount in range(1,7):
                                  print('You have selected tickets '.format(amount))
                                  elif amount == (0):
                                  print('You have selected 0 tickets')
                                  else:
                                  print('Please choose an amount between 0-6')





                                  share|improve this answer



























                                    0














                                    Instead of using if amount == range(1,7): use if amount in range(1,7):



                                    This is the modified code that you should use:



                                    def quantity():
                                    global amount
                                    amount = input('How many tickets are you looking for? ')
                                    if amount in range(1,7):
                                    print('You have selected tickets '.format(amount))
                                    elif amount == (0):
                                    print('You have selected 0 tickets')
                                    else:
                                    print('Please choose an amount between 0-6')





                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      Instead of using if amount == range(1,7): use if amount in range(1,7):



                                      This is the modified code that you should use:



                                      def quantity():
                                      global amount
                                      amount = input('How many tickets are you looking for? ')
                                      if amount in range(1,7):
                                      print('You have selected tickets '.format(amount))
                                      elif amount == (0):
                                      print('You have selected 0 tickets')
                                      else:
                                      print('Please choose an amount between 0-6')





                                      share|improve this answer













                                      Instead of using if amount == range(1,7): use if amount in range(1,7):



                                      This is the modified code that you should use:



                                      def quantity():
                                      global amount
                                      amount = input('How many tickets are you looking for? ')
                                      if amount in range(1,7):
                                      print('You have selected tickets '.format(amount))
                                      elif amount == (0):
                                      print('You have selected 0 tickets')
                                      else:
                                      print('Please choose an amount between 0-6')






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 15 '18 at 5:07









                                      Siddharth SatpathySiddharth Satpathy

                                      6291817




                                      6291817





















                                          -1














                                          input returns a string, so I guess you should be doing amount = int(input('...')).






                                          share|improve this answer























                                          • Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

                                            – Emil Vatai
                                            Nov 15 '18 at 5:04















                                          -1














                                          input returns a string, so I guess you should be doing amount = int(input('...')).






                                          share|improve this answer























                                          • Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

                                            – Emil Vatai
                                            Nov 15 '18 at 5:04













                                          -1












                                          -1








                                          -1







                                          input returns a string, so I guess you should be doing amount = int(input('...')).






                                          share|improve this answer













                                          input returns a string, so I guess you should be doing amount = int(input('...')).







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Nov 15 '18 at 4:59









                                          Emil VataiEmil Vatai

                                          1,0941013




                                          1,0941013












                                          • Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

                                            – Emil Vatai
                                            Nov 15 '18 at 5:04

















                                          • Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

                                            – Emil Vatai
                                            Nov 15 '18 at 5:04
















                                          Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

                                          – Emil Vatai
                                          Nov 15 '18 at 5:04





                                          Am I missing something? Ahh... the in not == is also important... but I don't think that was the main concern of OP.

                                          – Emil Vatai
                                          Nov 15 '18 at 5:04

















                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312657%2fif-statement-only-printing-else%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Darth Vader #20

                                          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                                          Ondo