def main(): while True: choice = get_user_choice(main_menu) if choice == 1: pet_name = input("What would you like to name your pet?\n") print("Please choose the type of pet:") type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) pets.append(Pet(pet_name)) print("You now hae %s pets" % len(pets)) if choice == 2: for pet in pets: pet.get_love() if choice == 3: for pet in pets: pet.eat_food() if choice == 4: for pet in pets: print(pet) if choice == 5: for pet in pets: pet.get_toy(Toy()) if choice == 6: for pet in pets: pet.be_alive() if choice == 7: print("Thanks for playing!!!") break
def test_pet_has_details(): d1 = {"age": 3, "sex": "female"} p1 = Pet(**d1) assert p1.name == "molly" assert p1.species == "dog" d2 = {"name": "frank", "species": "spider"} p2 = Pet(**d2) assert p2.name == "frank" assert p2.species == "spider"
def main(): while True: choice = get_user_choice(main_menu) #allowing user to adopt a pet if choice == 1: pet_name = input("What would you like to name your pet? ") print("Please choose the type of pet:") type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) print("You now have %d pets" % len(pets)) if choice == 2: for pet in pets: pet.get_love() if choice == 3: for pet in pets: pet.eat_food() #View pet status if choice == 4: for pet in pets: print(pet) if choice == 5: for pet in pets: pet.get_toy(Toy()) if choice == 6: # Pet levels naturally lower. for pet in pets: pet.be_alive()
def test_pet_has_age_and_sex(): d = {"age": 7, "sex": "male"} p = Pet(**d) assert p.name == "molly" assert p.species == "dog" assert p.age == 7 assert p.sex == "male"
def test_updatePet(): pet = Pet(201, 202, 'sparrow', 'available') put_Res = update_pet_name_and_status(pet) print(put_Res.status_code) print(put_Res.json()) assert put_Res.json()['name'] == 'sparrow' assert put_Res.json()['status'] == 'available'
def main(): while True: clear() choice = get_user_choice(main_menu) if choice == 1: pet_name = input("What would you like to name your pet? ") print("Please choose the type of pet:") type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) print("You now have %d pets" % len(pets)) if choice == 2: for pet in pets: pet.get_love() if choice == 3: for pet in pets: pet.eat_food() if choice == 4: for pet in pets: pet.get_toy(Toy()) if choice == 5: for pet in pets: print(pet) input("") if choice == 6: for pet in pets: pet.be_alive() if choice == 7: clear() print("Thanks for adopting and taking care of your pet.") return False
def test___str__(self, mock_get_complex_object, mock_get_age, mock_get_species): mock_get_complex_object.return_value = Random() mock_get_age.return_value = 12 mock_get_species.return_value = 'Dog' pet_instance = Pet('Clifford', 'Dog', 12) self.assertEqual(pet_instance.__str__(), 'Random Clifford is a dog aged 12')
def test_exercise(): os.chdir('src') from pet import Pet from person import Person lucky = Pet("Lucky", "collie") james = Person("James", lucky) assert str(james) == "James, has a friend called Lucky (collie)"
def play(): animals = [] option = "" base_prompt = """ Quit Adopt <petname_with_no_spaces_please> Greet <petname> Teach <petname> <word> Feed <petname> Choice: """ feedback = "" while True: action = input(feedback + "\n" + base_prompt) feedback = "" words = action.split() if len(words) > 0: command = words[0] else: command = None if command == "Quit": print("Exiting...") return elif command == "Adopt" and len(words) > 1: if whichone(animals, words[1]): feedback += "You already have a pet with that name\n" else: animals.append(Pet(words[1])) elif command == "Greet" and len(words) > 1: pet = whichone(animals, words[1]) if not pet: feedback += "I didn't recognize that pet name. Please try again.\n" print() else: pet.hi() elif command == "Teach" and len(words) > 2: pet = whichone(animals, words[1]) if not pet: feedback += "I didn't recognize that pet name. Please try again." else: pet.teach(words[2]) elif command == "Feed" and len(words) > 1: pet = whichone(animals, words[1]) if not pet: feedback += "I didn't recognize that pet name. Please try again." else: pet.feed() else: feedback += "I didn't understand that. Please try again." for pet in animals: pet.clock_tick() feedback += "\n" + pet.__str__()
def load_petData(): with open(pet_file, 'r', newline='') as csvfile: reader = list(csv.reader(csvfile)) #skip first row because of labels first = True for row in reader: if first: first = False else: list_pet.append( Pet(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10]))
def enter(): global cookie, stage, pet, game_timer, gameinfo, hp_time game_timer = get_time() hp_time = get_time() cookie = Cookie() gameinfo = GameInfo() stage = Stage() pet = Pet() game_world.objects = [[], [], [], []] game_world.add_object(stage, 0) game_world.add_object(cookie, 1) game_world.add_object(pet, 2) game_world.add_object(gameinfo, 3)
def main(): while True: choice = get_user_choice(main_menu) if choice == 1: pet_name = input( u"\n\u001b[32;1m Please enter the name of your new pet: \u001b[0m\n" ) print( u"\u001b[35;1m\n What type of pet would you like to adopt? \u001b[0m\n" ) type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(PlayfulPet(pet_name)) print(u"\n\u001b[35;1m Extra playful!! \u001b[0m\n") print("You now have %d new pet(s) \n" % len(pets)) if choice == 2: for pet in pets: pet.get_love() print(u"\u001b[32;1m This is fun! Let's play all day\u001b[0m") if choice == 3: print( u"\n\u001b[32;1m What kind of treat would you like to give your pet? \u001b[0m\n" ) for pet in pets: type_treat = get_pet_treat(treat_list) my_treat = treat_list[type_treat] print(my_treat.message) results = my_treat.give_treat() pet.happiness += results[1] pet.hunger -= results[0] if choice == 4: for pet in pets: pet.eat_food() print(u"\u001b[32;1m YUM! That hit the spot! \u001b[0m") if choice == 5: for pet in pets: pet.nap_time() print(u"\u001b[32;1m Nap time!...I'm sleepy. \u001b[0m") if choice == 6: for pet in pets: print(pet) if choice == 7: for pet in pets: pet.get_toy(Toy()) if choice == 8: for pet in pets: pet.life() if choice == 9: exit(print(u"\u001b[42m Please, come back soon! \u001b[0m\n"))
def main(): again = 'y' while again.lower() == 'y': pet_name = input('Pet name: ') pet_type = input('Pet type: ') pet_age = input('Pet age: ') the_pet = Pet(pet_name, pet_type, pet_age) print() print(the_pet) again = input('Again? (y/n): ')
def on_receive(j): window.requestAnimationFrame(step) for pid, owner, name, dna in j: if pid not in pets_by_id: pet = Pet() pet.pid = pid pet.owner = owner if owner else 0 pet.name = name if name else "boss" pets_by_id[pet.pid] = pet pets.append(pet) else: pet = pets_by_id[pid] pet.from_json(dna) pet.make_balls()
def main(): print("\033c") while True: choice = get_user_choice(main_menu) if choice == 1: pet_name = input("What would you like to name your pet? ") print("Please choose the type of pet: ") type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) print("You now have %d pets" % len(pets)) transition() if choice == 2: for pet in pets: pet.get_love() print("All your pets are now a little happier!\n") transition() if choice == 3: for pet in pets: pet.eat_food() print("All your pets are now a little more full!\n") transition() if choice == 4: if pets != []: for pet in pets: print(pet) else: print("You don't have any pets right now.\n") transition() if choice == 5: for pet in pets: pet.get_toy(Toy()) print("You gave all your pets a toy!\n") transition() if choice == 6: for pet in pets: pet.be_alive() transition()
def __init__(self): self.pos: Tuple = 150, get_canvas_height() // 2 self.delta: Tuple = 0, 0 self.pet = Pet(*self.pos, self) gfw.world.add(gfw.layer.player, self.pet) self.state = None self.set_state(RunningState) self.bb_idx = 0 self.score = 0 # each meso's score self.ea_score = 0 self.invincible = 0 self.life_gauge = LifeGauge(10, 10) gfw.world.add(gfw.layer.ui, self.life_gauge)
def main(): #copied and pasted while True: choice = get_user_choice(main_menu) if choice == 1: pet_name = input("What would you like to name your pet? ") print("Please choose the type of pet:") type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append( Pet(pet_name) ) #still not sure why error ***had incorrect vlaues for methods FIXED elif type_choice == 2: pets.append(CuddlyPet(pet_name)) print("You now have %d pets" % len(pets)) if choice == 4: for pet in pets: print(pet)
def main(): main = Menu("Please choose an option:", main_menu) type = Menu("Please choose the type of pet:", adoption_menu) treat = Menu("Please choose the type of treat:", treat_menu) while True: choice = main.get_choice() if choice == 1: pet_name = input("What would you like to name your pet? ") type_choice = type.get_user_choice() if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) print("You now have %d pets" % len(pets)) if choice == 2: for pet in pets: pet.get_love() print("Pets have been loved!") if choice == 3: for pet in pets: pet.eat_food() print("Pets have been fed!") if choice == 4: for pet in pets: print(pet) if choice == 5: for pet in pets: pet.get_toy(Toy()) print("Pets got a toy!") if choice == 6: treat_choice = treat.get_user_choice() if treat_choice == 1: treat_type = ColdPizza() if treat_choice == 2: treat_type = Bacon() if treat_choice == 3: treat_type = VeganSnack for pet in pets: pet.get_treat(treat_type) print("Pets got a treat!") if choice == 7: for pet in pets: pet.be_alive() print("Pets did nothing!")
def main(): app = Menu("Please choose an option", main_menu) types = Menu("Please choose a type of pet", adoption_menu) treats = Menu("please choose a type of treat", treat_menu) while True: choice = app.get_user_choice() if choice == 1: pet_name = input("What would you like the pet name to be?") type_choice = types.get_user_choice() if type_choice == 1: pets.append(Pet(pet_name)) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) num_pets = len(pets) print(f"You now have {num_pets} pets") elif choice == 2: for pet in pets: pet.get_love() elif choice == 3: for pet in pets: pet.eat_food() elif choice == 4: for pet in pets: print(pet) elif choice == 5: for pet in pets: pet.get_toy(Toy()) elif choice == 6: for pet in pets: pet.be_alive() elif choice == 7: print("Please choose your type of treat:") treat_choice = treats.get_user_choice if treat_choice == 1: for pet in pets: pet.eat_treat(ColdPizza()) elif treat_choice == 2: for pet in pets: pet.eat_treat(Bacon()) elif treat_choice == 3: for pet in pets: pet.eat_treat(VeganSnack())
def __init__(self, name="unknown", surname="unknown", year=0, iq=0, pet="unknown", mother='unknown', father='unknown', schedule=None): self.__name = name self.__surname = surname self.__year = int(year) if 0 <= iq <= 100: self.__iq = iq self.__pet = Pet(pet) self.__mother = Human(mother) self.__father = Human(father) if schedule is None: schedule = [] else: self.__schedule = list(schedule)
def main(): app = Menu('Please choose an Option: ', main_menu) types = Menu('Please choose a Pet Option: ', adoption_menu) treats = Menu('Please choose a Treat Option: ', menu_menu) while True: choice = app.get_choice() if choice == 1: pet_name = input('What do you want to name your pet?') type_choice = types.get_choice() if (type_choice == 1): pets.append(Pet(pet_name)) elif (type_choice == 2): pets.append(CuddlyPet(pet_name)) print(f'\n\nYou now have {len(pets)} pets') elif choice == 2: for pet in pets: pet.get_love() elif choice == 3: treat_choice = treats.get_choice() food_to_feed = 0 if(treat_choice == 1): food_to_feed = ColdPizza() elif(treat_choice == 2): food_to_feed = Bacon() elif(treat_choice == 3): food_to_feed = VeganSnack() for pet in pets: pet.eat_food(food_to_feed) elif choice == 4: for pet in pets: print(pet) elif choice == 5: for pet in pets: pet.get_toy(Toy()) elif choice == 6: for pet in pets: pet.be_alive() print(pet)
from pet import Pet from dog import Dog # Pet myPet = Pet() myPet.petName = input() myPet.petAge = int(input()) myPet.printInfo() # Dog myDog = Dog() myDog.petName = input() myDog.petAge = input() myDog.dogBreed = input() myDog.printInfo()
from pet import Pet pets = list() #an empty list that will store all the pets in the shops #initialize and describe Spot the Dog. spot = Pet('Spot') spot.set_animal('dog') spot.set_description('Short legged, white fur with a single black spot') ''' spot.set_noise('Woof!') ''' pets.append(spot) #initialize and describe Shadow the Cat. shadow = Pet('Shadow') shadow.set_animal('cat') shadow.set_description( 'Shy, with all dark fur. She likes to hide behind furniture.') ''' shadow.set_noise('Meow!') ''' pets.append(shadow) ''' Add your own pet(s) here ''' #Customer Interaction with the Pets print('Welcome to My Pet Shop!') current_pet = pets[0] while True: print('\n') print('Choose the pet that you would like to meet.') for index, pet_name in enumerate(pets): #prints a list of pets print(index, pet_name.get_name())
from pet import Pet mypet = Pet('ian', 2) print(mypet) print(mypet.get_name()) print(mypet.get_age())
from dog import Dog from pet import Pet pupper = Dog("Border Collie") doggo = Pet("Doggo", pupper) doggo.assign_owner("Cole") print(doggo)
def main(): while True: choice = get_user_choice(main_menu) if choice == 1: pet_name = input("What would you like to name your pet? ") print("Please choose the type of pet:") type_choice = get_user_choice(adoption_menu) if type_choice == 1: pets.append(Pet(pet_name)) print( "Good choice, these pets are great to start your journey as pet owner.\n" ) elif type_choice == 2: pets.append(CuddlyPet(pet_name)) print( "Great choice, these pets are great for one's mental health and great anxiety reducers. But they do require lots of attention.\n" ) print("You now have %d pets.\n" % len(pets)) ### first part of the main menu #### when a choice is made it starts the loop of choices elif choice == 2: for pet in pets: pet.get_love() if pet.happiness >= 8 and pet.happiness < 10: print( f"{pet_name}, is very happy, may want rest a bit. \n") elif pet.happiness >= 10: print(f"{pet_name} is very tired and needs to rest. \n") elif choice == 3: for pet in pets: pet.eat_food() if pet.fullness >= 8 and pet.fullness < 10: print( f"{pet_name}, is statisfied, you can stop feeding it. \n" ) elif pet.fullness >= 10: print( f"{pet_name} has over eatten, and now needs to sleep. \n" ) elif choice == 4: for pet in pets: print(pet) elif choice == 5: for pet in pets: pet.get_toy(Toy()) elif choice == 6: # Pet levels naturally lower. for pet in pets: pet.be_alive() if pet.happiness <= 3 and pet.happiness > 0: print( f"{pet_name} is sad, you may want to play with your pet.\n" ) elif pet.fullness <= 3 and pet.fullness > 0: print( f"{pet_name} is hungry, you may want to feed your pet.\n" ) elif pet.fullness <= 0: print( f"{pet_name}, has died of hunger. Expect a call from the authorities!!!\n" ) break elif pet.happiness <= 0: print( f"{pet_name}, has run away, you may want to reflect of your life choices!\n" ) break ### when this choice is made, depending on the level pet is already, parameter is set to notify the user of pets health and happiness. elif choice == 7: print("Thanks for playing, tell your friends! \n") break
c = conn.cursor() sql = "INSERT INTO pets (name, species, age, sex) values ('{}', '{}', {}, '{}')".format( pet.name, pet.species, pet.age, pet.sex) c.execute(sql) conn.commit() conn.close() while True: response = input("(e)nter a pet, open a (f)ile, or (q)uit: ") print(response) if response == 'q': break if response == 'e': name = input("name: ") species = input("species: ") age = input("age: ") sex = input("sex: ") p = Pet(name, species, age, sex) print('pet:', p) db_insert(p) # adds pet to database using function above if response == 'f': file = input("filename: ") with open(file) as f: for line in f: name, species, age, sex = line.strip().split(',') p = Pet(name, species, age, sex) print("p: ", p) db_insert(p) # adds pet to database using function above
def test_get_name(self): pet_instance = Pet('Clifford', 'Dog', 12) self.assertEqual(pet_instance.get_name(), 'Clifford')
def main(): pet = Pet() print(pet)
def test_pet_has_name(): p = Pet("fido") assert p.name == "fido"