мой код довольно грязный, поскольку я новичок, но я не могу понять это!
Между прочим, я включил только соответствующие фрагменты моего кода.
Практически все, что я хочу сделать, это сказать одно и то же местоположение дважды для random_place1 и затем новое местоположение для random_place2. В настоящее время он просто дает мне три отдельных местоположения, потому что я просто призываю random_place1 переназначить.
def random_place1():
import random
locations = ["Paris" , "New York", "San Francisco" , "Tokyo", "Istanbul", "São Paulo", "Xi'an", "Bogotá", "Casablanca", "Rabat"]
first_place = random.choice(locations)
return (first_place)
def random_place2():
import random
locations = ["London" , "Miami" , "Chicago", "Cairo", "Vienna" , "Manila", "Munich", "Delhi"]
second_place = random.choice(locations)
return(second_place)
def main():
answer = input("Type Yes to continue or No to exit: ")
if answer == "yes":
print("\nLast summer, we went for a vacation with " + random_name(), "on a trip to " + random_place1(), ". The weather there is very " + random_adj(), "! Northern " + random_place1(), " has many " + random_plural_noun(), ", and they make " + random_plural_noun(), " there. Many people there also go to the " + random_place2()," to " + random_action_verb(), ". The people who live there like to eat " + random_food(), ". They also like to " + random_action_verb(), " in the sun and swim in the " + random_noun(), ". It was a really " + random_adj(), " trip!")
restart2()
elif answer == "y" :
print("\nLast summer, we went for a vacation with " + random_name(), "on a trip to " + random_place1(), ". The weather there is very " + random_adj(), "! Northern " + random_place1(), " has many " + random_plural_noun(), ", and they make " + random_plural_noun(), " there. Many people there also go to the " + random_place2()," to " + random_action_verb(), ". The people who live there like to eat " + random_food(), ". They also like to " + random_action_verb(), " in the sun and swim in the " + random_noun(), ". It was a really " + random_adj(), " trip!")
restart2()
elif answer == "Yes":
print("\nLast summer, we went for a vacation with " + random_name(), "on a trip to " + random_place1(), ". The weather there is very " + random_adj(), "! Northern " + random_place1(), " has many " + random_plural_noun(), ", and they make " + random_plural_noun(), " there. Many people there also go to the " + random_place2()," to " + random_action_verb(), ". The people who live there like to eat " + random_food(), ". They also like to " + random_action_verb(), " in the sun and swim in the " + random_noun(), ". It was a really " + random_adj(), " trip!")
restart2()
elif answer == "YES":
print("\nLast summer, we went for a vacation with " + random_name(), "on a trip to " + random_place1(), ". The weather there is very " + random_adj(), "! Northern " + random_place1(), " has many " + random_plural_noun(), ", and they make " + random_plural_noun(), " there. Many people there also go to the " + random_place2()," to " + random_action_verb(), ". The people who live there like to eat " + random_food(), ". They also like to " + random_action_verb(), " in the sun and swim in the " + random_noun(), ". It was a really " + random_adj(), " trip!")
restart2()
elif answer == "Y":
print("\nLast summer, we went for a vacation with " + random_name(), "on a trip to " + random_place1(), ". The weather there is very " + random_adj(), "! Northern " + random_place1(), " has many " + random_plural_noun(), ", and they make " + random_plural_noun(), " there. Many people there also go to the " + random_place2()," to " + random_action_verb(), ". The people who live there like to eat " + random_food(), ". They also like to " + random_action_verb(), " in the sun and swim in the " + random_noun(), ". It was a really " + random_adj(), " trip!")
restart2()
elif answer == "no":
print("\nThanks for trying out the Madlibs Generator!")
elif answer == "n":
print("\nThanks for trying out the Madlibs Generator!")
elif answer == "No":
print("\nThanks for trying out the Madlibs Generator!")
elif answer == "NO":
print("\nThanks for trying out the Madlibs Generator!")
elif answer == "N":
print("\nThanks for trying out the Madlibs Generator!")
else:
print("\nInvalid response please try again!")
restart()