Conditional not working

em, so the problem here is , when i reach to the part where the code runs DEAD == true , the first function doesnt recognize this part where it should be , this is my first project i am planning to do a really long time and i am a rookie basically, so all the help will be appreciated

DEAD = "False"
urrent_Melee_Weapon = ""
Current_Ranged_Weapon = ""
Current_Magic_Weapon = ""

MeleeATK = 0
RangedATK = 0
MagicATK = 0
Health_Pack = 0

answer_count = 0
fudge_up = 0

while answer_count == 0 and fudge_up < 3 and DEAD == "False":
	Intro = input ("<>Hey you! Answer 'yes' or I gonna bang you in the head!!! (Yes//No) : ").lower().strip()
	if Intro == "yes":
		answer_count += 1
		print (answer_count)

		print ("<>So heres the thing : WWIII broke out and as a soldier you are now in a army camp in Area 51,")
		print ("<>Here are some of your equipment : ")
		print ("< Army Knife > : MeleeATK + 2")
		MeleeATK += 2
		Current_Melee_Weapon = "Army Knife"

		print ("< Glock 18 > : RangedATK + 2")
		RangedATK += 2
		Current_Ranged_Weapon = "Glock 18"

		print ("< Health Pack > [2]")
		Health_Pack += 2
		Health_Pack_Pos = True

		print ("<>Oh shet!")
		print ("<>The Neo-Nazis are coming! They have fudging missles and tanks and ship!")
		print ("<>Incoming a Nazi Soldier towards your way...")
		answer = input ("<>Wut ya gonna do? (Attack//Escape) : ").lower().strip()

		if answer == "attack" and answer_count == 1:
			answer_count += 1
			print (answer_count)

			print ("<>The Nazi dude rushes your way and pulls out his HK417...")
			print ("*PANIC*")
			answer = input ("<>What ya gonna attack him with? (" + Current_Melee_Weapon + "//" + Current_Ranged_Weapon + ") : ").lower().strip()

		elif answer == "escape" and answer_count == 1:
			answer_count += 1
			print (answer_count)

			print ("<>As the largest coward in the whole fudging universe, you tried to run away...")
			print ("<>But the Nazis had supreme Athletic Training and you are just a weebo that somehow joined the army,")
			print ("<>you have no choice but to fight him!!!")
			print ("*PANIC*")
			answer = input ("<>What ya gonna attack him with? (" + Current_Melee_Weapon + "//" + Current_Ranged_Weapon + ") : ").lower().strip()

		else:
			print ("<>You were so fudging messed up you arent even sure what ya wanna do,")
			print ("<>The next thing you know, the Nazi dude shot the fudging outta you, you died, the end...")

	elif Intro == "no" or fudge_up == 2:
		print (answer_count)

		print ("<>OK if this is what you wanted the whole time, fudge you. Get rekt.")
		print ("*Gets shot in the head*")
		print ("<>And of course you died being a useless rexxxx")

	else:
		fudge_up += 1
		print (answer_count)

		print ("<>Invalid Answer")
		print ("<>Try again...")
		DEAD == "True"

No. You can edit them out. This topic will remain unlisted until you do.

1 Like

yah just did thanks for reminding

2 Likes

Forgive me perhaps I misunderstood your question.

Your code seems to work almost perfectly, every question seems to work correctly, and updates all of the variables accurately.

What are you wanting the code to do when DEAD = "True"?
Unless this is not all of your code, the program ends when it gets there.

You also mentioned a function, which also leads me to think there is possibly more code.

so what i was thinking to happen is, when DEAD = “True” runs as the else of the first function , the first function will stop running and and thus “game over”, the reason i tried"True" instead of just True and False was because none of them are working

and there is no more code, the this is the whole thing shipping to the forums

Ok I think I get what you mean, and I actually missed this the first time around.
If I understand correctly you are wanting the while loop to end once DEAD is equal to "False"

Your last line is using the equality operator == which checks if something is equal.
Instead of using the assignment operator = which is used to give something a value.


On the side, a function refers to a portion of code that can be reused by calling its name:

def add(n1, n2):       # creates a function that takes two arguements
  return n1 + n2       # returns the result of adding the two arguements

a = add(5, 7)          # creates a variable equal to calling add() on 5
                       # and 7

print(a)               #prints the new variable, which is equal to 12

I am unsure if you have gotten to the lesson of functions yet, I don’t remember if loops came first or not.

oh sorry i guess i mixed up functions and statements

1 Like

so i shd replace == with =?

1 Like

so i updated the code and replaced the “true” “false” to true false and also changed the lower and the == in the first if statement and the code still isnt working properly

DEAD = False
urrent_Melee_Weapon = ""
Current_Ranged_Weapon = ""
Current_Magic_Weapon = ""

MeleeATK = 0
RangedATK = 0
MagicATK = 0
Health_Pack = 0

answer_count = 0
fudge_up = 0

while answer_count == 0 and fudge_up < 3 and DEAD = False:
	Intro = input ("<>Hey you! Answer 'yes' or I gonna bang you in the head!!! (Yes//No) : ").lower().strip()
	if Intro == "yes":
		answer_count += 1
		print (answer_count)
.......................................
    elif Intro == "no" or fudge_up == 2:
		print (answer_count)

		print ("<>OK if this is what you wanted the whole time, fudge you. Get rekt.")
		print ("*Gets shot in the head*")
		print ("<>And of course you died being a useless rexxxx")

	else:
		fudge_up += 1
		print (answer_count)

		print ("<>Invalid Answer")
		print ("<>Try again...")
		DEAD = True

this is what pops up when it runs:
<>Hey you! Answer ‘yes’ or I gonna bang you in the head!!! (Yes//No) : x
0
<>Invalid Answer
<>Try again…
<>Hey you! Answer ‘yes’ or I gonna bang you in the head!!! (Yes//No) : x
0
<>Invalid Answer
<>Try again…
<>Hey you! Answer ‘yes’ or I gonna bang you in the head!!! (Yes//No) : x
0
<>OK if this is what you wanted the whole time, fudge you. Get rekt.
Gets shot in the head
<>And of course you died being an idiot
<>Hey you! Answer ‘yes’ or I gonna bang you in the head!!! (Yes//No) :

I think your indentation got messed up when you reposted.


Your while loop is now using the assignment operator =
When checking for a condition in an if or a while you want to use the equality operator ==

Because of this your while, on line 14, will loop at least three times until stopping because it is no longer checking for the condition of DEAD.

The only reason it stops at all is because fudge_up is being incremented every time the else statement runs.

so what shd i correct if i want my code to stop at 3 times exact when the DEAD becomes True and nothing else pops up

I would increment fudge_up inside of your elif statement.


Also since you wanna give the player x amount of tries I don’t think your else statement should change DEAD to True.

If you do this and your while loop is checking for the status of DEAD than the game will end if someone imputs an invalid entry

1 Like

Off topic…

DEAD by convention would be a global constant. Since we can set it, that means it is variable.

dead = True

or the less arbitrary,

dead = not dead

== ?
    and not dead:
2 Likes
from random import choice

class Player:
    def __init__(self):
        self.dead = False
    def toggle(self):
        self.dead = not self.dead
    def shot(self):
        return choice([0, 1])

us = Player(), Player()
you, me = us

while True:
    if you.dead and me.dead: break
    if you.shot(): you.toggle(); print ("You're hit!")
    if me.shot(): me.toggle(); print ("I'm hit!")

print ('Bye!')
>>> 
= RESTART: C:/Users/Mr/AppData/Local/Programs/Python/Python38/Scripts/shells/player_shot_dead.py
I'm hit!
You're hit!
I'm hit!
You're hit!
I'm hit!
You're hit!
I'm hit!
You're hit!
You're hit!
I'm hit!
Bye!
>>> 
2 Likes

i wish i know better
on how to use defs ://

Ignore the above and pour yourself into the lessons and followup reading. Make sure you read the documentation on every new concept your learn.

docs.python.org

Or you can search,

def py

The second term tells the search engine to only show python results.

Perhaps I’m jumping ahead, so must apologize. That’s not fair. Stick it to the conditional unit before you move on. Functions will come up. As you will learn, they depend upon what you’re learning right now so dig in!

2 Likes