Python undefined name 'Function name' error

Asked 2 years ago, Updated 2 years ago, 161 views

//
import random

print ("Name Generation")

Main character = input()
print "The name of the main character"
      f"{Heroine}")

while 1:
    power = random.randrange(3, 9)
    health = random.randrange(5, 9)
    mana = random.randrange(1, 5)
    luck = random.randrange(0, 3)

    print(f"power = {power}, health = {health}, mana = {mana}, luck = {luck}")
    print("Restat? Y/N")

    A = input()
    if A == "Y":
        print("GAME START")

    if A == "N":
        print("OK GOD BLESS YOU")

    B = input()
    if B == "Y":
        continue

    elif B == "N":
        print("Setting Complete")
        print(f"""
 [Status]
 Name = {Heroine}
 occupation = adventurer
 Physical strength = {health}
 Combat power = {power}
 Luck = {lucky}
 Mana = {mana}"")

    break
print(" WARING! WARING!  ")
print(" !ENEMY FOUND!")
print("")

enemyH = 30
enemyD = 5
enemyA = 5
enemyM = 3

health1 = health
power1 = power
mana1 = mana
luck1 = luck

while 1:
    print("my turn")
    G = input("a)attack d)defense s)skill r)run  \n")
    if G == "a":
        print("knife Throwing!")
        power1 = power + random.choice([1, 2, 3, 6, 8])
    if power1 - enemyD <= 0:
        print("MISS")
        enemyD -= power1
    else:
        enemyH -= (power1 - enemyD)
        print(f"enemy health = {enemyH}")
        enemyD = 0
        break

G == random.randrange(1, 4), input("y)YES n)NO")
print("\n enemy turn")
if G == 1:
    enemyA1 = enemyA + random.choice([1, 2, 5, 9, 7])
    if enemyA1 - health <= 0:
        print("MISS^^")
        health -= enemyA1
    else:
        print("double attack")
        health -= (enemyA1 - health)
        print(f"{Heroine}'s remaining stamina = {health}")
        health = 0

elif G == 2:
    enemyD += 3 + random.randrange([1, 7])
    print "I don't think I can win")
elif G == 3:
    enemyM += 2
    print("SNOW RAIN")
    health -= random.choice([
        10,
        20,
        25,
    ])
    print(f"{main character} = {health}")
    ememyM = 0

if health <= 0:
    G == input("y)YES n)NO")
    print("lose...OTL")
    Count = input("RETRY? y:YES n:NO ")

elif G == y: <<<<< undefined name 'y'

    print("LOADING... WAIT FOR SECOND...")
    health = health1
    enemyA = 5
    enemyH = 50
    enemyD = 0

else:

<< They say they can't find the name y in the marked place, but I don't know how to put it in

python name error function

2022-09-25 01:00

1 Answers

undefined name '{NAME}'

Indicates that a variable named NAME is not specified.


2022-09-25 01:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.