In the video game Animal Crossing: New Horizons, villagers are organized by Personality and Hobby. The 8 Personalities are:
Normal
Lazy
Sisterly
Snooty
Cranky
Jock
Peppy
Smug
The 6 Hobbies are:
Education
Fashion
Fitness
Music
Nature
Playing
Create a program that allows the user to create their own Animal Crossing villager. The user should be able to enter a name, after which the program will choose a random Hobby and Personality for the villager:
Please enter a Villager Name:
>> Betsy
Betsy is Snooty and into Nature
The program should store both the Hobbies and Personalities in lists, and when creating a villager it should randomly choose from each list for the personality.
Requirements: · Both Personalities and Hobbies must be stored in lists · You must generate a different random number to determine the hobby and personality (that is, don’t generate 1 random number and use it for both lists, as that prevents many combinations) · In randomizing, you should make sure that all combinations are possible (that is, make sure you don’t accidentally leave out a personality or hobby from random generation) · The program shouldn’t crash
So far, I’ve gotten the name part down which is:
name =str(input("Please enter a Villager Name:"))
print(str(name))
But I can’t figure out how to randomize the personalities and hobbies with a different number.
Advertisement
Answer
Here is My Code With Some Comments To Explain What I Did.
# Import Random Library:
from random import randrange
# Defining Personalities And Hobbies Lists:
personality_list = ["Normal", "Lazy", "Sisterly", "Snooty", "Cranky", "Jock", "Peppy", "Smug"]
hobby_list = ["Education", "Fashion", "Fitness", "Music", "Nature", "Playing"]
# Select Random Item From the lists:
personality = personality_list[randrange(len(personality_list))]
hobby = hobby_list[randrange(len(hobby_list))]
# Take User Input:
name = str(input("Please Enter A Villager Name: "))
# Print The Results:
print(f"{name} is {personality}, and into {hobby}.")
Output:
Please Enter A Villager Name: Zeid
Zeid is Normal, and into Education.
Note: In The Last Line I Used Something Called F String, Which only works With Python 3.6 or later. For more info about it and it’s alternatives, you can visit this page: https://realpython.com/python-f-strings/