gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
write a funny code in thonny for fun
- User
write a funny code in thonny for fun
- Assistant
Certainly! Here's a simple and funny little Python program you can try out in Thonny. It's a humorous take on a "virtual pet" that randomly generates some quirky characteristics for your new digital buddy.
import random class VirtualPet: def __init__(self, name): self.name = name self.species = random.choice(['Cat', 'Dog', 'Dragon', 'Unicorn', 'Platypus']) self.mood = random.choice(['Happy', 'Grumpy', 'Hungry', 'Sleepy', 'Hyperactive']) self.trick = random.choice(['Jump', 'Run in circles', 'Play dead', 'Sing', 'Dance']) def show_info(self): print(f"\nMeet your new virtual pet: {self.name}!") print(f"Species: {self.species}") print(f"Mood: {self.mood}") print(f"Favorite Trick: {self.trick}\n") def perform_trick(self): print(f"{self.name} is trying to {self.trick.lower()}... and it's hilarious!\n") # Main program def main(): pet_name = input("What would you like to name your virtual pet? ") pet = VirtualPet(pet_name) pet.show_info() while True: action = input("What would you like your pet to do? (show/perform/exit): ").strip().lower() if action == 'show': pet.show_info() elif action == 'perform': pet.perform_trick() elif action == 'exit': print(f"Goodbye! {pet.name} waves a paw/fin/hoof as you leave.") break else: print("Oops! I don't understand that command.") if __name__ == "__main__": main()