I'm struggling with some if statements - Python 2.7.9 (big noob) -


I want to make a part of a game where you only have a gun with a bullet. But you have two chances to use it so if you use it for the first time you can not use it for the second time, or vice versa. Ammo_amount = 1 ammo = raw_input ("shoot?") If ammo == 'y': print ("you shot") ammo_amount-1 else: print ("You did not shoot Ammo_2 = raw_input ("Do you want to shoot again?") If ammo_2 == 'y': if ammo_amount == '1': print ("You can shoot again") if ammo_amount == '0': print ("you can not shoot again") if ammo_2 == 'n': print ("you did not shoot")

< Div class = "post-text" itemprop = "text">

You are comparing the string with an integer:

  Ammo_amount = 1 # ... if ammo_amount == '1': # if ammo_a These tests will never be true; telegrams are never equal to integers if they are such characters that are used in the same number of times when reading text. Can be interpreted; Instead, compare to another number:  
  if ammo_amount == 1:  

and

  if ammo_amount == 0:  

You have never changed ammo_amount ; The following expression generates a new number:

  ammo_amount-1  

but you are ignoring that new number. Store it back in the ammo_amount variable:

  ammo_amount = ammo_amount - 1  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -