1

Below is a superhero name generator. I want to be able to add the name chosen to where it says go out and save the world. does anyone know how I can do this?

def superhero_name_generator():
    print("Welcome to the superhero name generator:\nTo choose your name follow the instructions below")
    first_part = input("Please enter the name of the city you grew up in. ")
    second_part = input("Please enter the name of your pet or your favorite mythical creature (Ie. Dragon). ")
    superhero_name = first_part + second_part
    print("your superhero name is {}".format(superhero_name))


end = '-'
while end != 0:
    superhero_name_generator()
    print("If you want to generate another name please press 1 to quit press 0")
    end = int(input())
else:
    print("Go out and save the world")
Samwise
  • 68,105
  • 3
  • 30
  • 44

2 Answers2

0

You'll have to return the value from the function. I also simplified your loop a little bit by making it an infinite one we break out of.

def superhero_name_generator():
    print("Welcome to the superhero name generator:\nTo choose your name follow the instructions below")
    first_part = input("Please enter the name of the city you grew up in. ")
    second_part = input("Please enter the name of your pet or your favorite mythical creature (Ie. Dragon). ")
    superhero_name = first_part + second_part
    print("your superhero name is {}".format(superhero_name))
    return superhero_name


while True:
    name = superhero_name_generator()
    print("If you want to generate another name please press 1 to quit press 0")
    if int(input()) == 0:
        break

print("Go out and save the world,", name)
AKX
  • 152,115
  • 15
  • 115
  • 172
0

Function returns super hero name using return function.

I have used name list to add all the supre hero name to it, so that it print all name.

def superhero_name_generator():
    print("Welcome to the superhero name generator:\nTo choose your name follow the instructions below")
    first_part = input("Please enter the name of the city you grew up in. ")
    second_part = input("Please enter the name of your pet or your favorite mythical creature (Ie. Dragon). ")
    superhero_name = first_part + second_part
    return superhero_name


end = 1
name = []
while end > 0 :
    var = superhero_name_generator()
    name.append(var)
    print("your superhero name is {}".format(var))
    print("If you want to generate another name please press 1 to quit press 0")
    end = int(input())
else:
    
    print("Go out and save the world",name)
Rima
  • 1,447
  • 1
  • 6
  • 12