コード例 #1
0
def main():
    '''
    The main program.
    '''

    # variables
    pets = ([None] * N_PETS)  # list of pets
    options = (list(range(1, N_PETS)) + [0])  # list of options
    callbacks = ((pet_menu, ) * N_PETS)  # list of callback
    #   functions of pets

    # stringify the options
    slew.stringify_in(N_PETS, options)
    options = tuple(options)

    # populate the list with pets
    for k in range(0, N_PETS):
        pets[k] = pet.Pet()
        # placeholder name before proper naming
        pets[k].set_name('Pet #' + str(k + 1))
    # end for k
    pets = tuple(pets)

    # main option menu
    slew.option_menu_apply(N_PETS, slew.create_legend('Pets:'), '',\
        options, get_pet_name, 'Choose a pet to manage. [default STOP]',\
        callbacks, pets, '\n> ', 'Invalid pet chosen.'\
    )

    # finish
    print('Done.')
コード例 #2
0
def main():

    tapio = student.Student("Tapio", "Koskinen", 1800509)
    musti = pet.Pet("Dog", "Musti", "Tapio")
    mimosa = pet.Pet("Cat", "mimosa", "Tapio")

    print("Test with empty")
    tapio.print_pets()
    tapio.add_pets(musti)
    print("After musti")
    print(tapio.print_pets())
    tapio.add_pets(mimosa)
    print("After mimosa")
    print(tapio.print_pets())

    print("Here is", tapio.get_first_name(), "and his pet(s):")
    print(tapio)
コード例 #3
0
def main():
	name = input("Enter the name of the pet: ") # retrieves the name of the pet
	animalType = input("Enter the type of animal: ") # retrieves the type of pet
	age = int(input("Enter the age of the pet: ")) # retrieves the age of the pet
	
	Pet1 = pet.Pet(name, animalType, age) # creates a pet object

	printOutput(Pet1) # prints the data of the pet

	return # ends program
コード例 #4
0
ファイル: pet_test.py プロジェクト: 507-w20-instructors/dyu2
    def testTeach(self):
        p1 = pet.pets[0]
        p2 = pet.Pet("rufus")

        self.assertEqual(len(p1.words), 2)
        self.assertEqual(len(p2.words), 2)

        p1.teach("hello")

        self.assertEqual(len(p1.words), 3)
        self.assertEqual(len(p2.words), 2)
コード例 #5
0
def get_me():
    user_id = oauth.check_auth(request)
    #user_id = 0
    if user_id is None:
        return '', 401

    answer = owner.Owner(user_id).json()[0]
    pets = pet.Pet.db()(owner_id = user_id)
    for item in pets:
        answer += pet.Pet(item['__id__']).json()[0]
    return answer
コード例 #6
0
def main():
    name = input('Кличка животного: ')
    type_pet = input('Кто это, собака, кошка...: ')
    age = int(input('Возраст: '))
    my_pet = pet.Pet(name, type_pet, age)

    print()
    print('Вот что Вы вводили:')
    print('Кличка -', my_pet.get_name())
    print('Тип животного -', my_pet.get_animal_type())
    print('Ему лет -', my_pet.get_age())
コード例 #7
0
ファイル: pet2.py プロジェクト: osnaldy/Python-StartingOut
def main():
    name = raw_input("Enter the name of the pet: ")
    animal_type = raw_input("Enter the Type of the animal: ")
    age = raw_input("Enter the age of the pet: ")
    print

    pets = pet.Pet(name, animal_type, age)

    print "Here is the data you have entered"
    print
    print "Name:", pets.get_name()
    print "Type of Animal:", pets.get_animal_type()
    print "Animal's Age:", pets.get_age()
コード例 #8
0
def main():
    # Create new Pet object
    newpet = pet.Pet()

    # Get pet info from user input
    newpet.set_name(input('What\'s your pet\'s name? '))
    newpet.set_animal_type(input('What kind of animal is your pet? '))
    newpet.set_age(int(input('How old is your animal? ')))

    # Output information recieved from user
    print('Your pet\'s name is ', newpet.get_name())
    print('Your pet is a ', newpet.get_animal_type())
    print('Your pet\'s age is ', newpet.get_age())
コード例 #9
0
ファイル: game.py プロジェクト: tombeek111/duo
 def create_objects(self,):
     import pet as _pet
     import controller as _controller
     import user_manager as _user_manager
     import scheduler as _scheduler
     import settings as _settings
     
     
     self.pet = _pet.Pet()
     self.controller = _controller.Controller()
     self.user_manager = _user_manager.UserManager()
     self.scheduler = _scheduler.Scheduler()
     self.settings = _settings.Settings()
コード例 #10
0
def main():
    print("\nWelcome To the Pet Program!")

    pet_name = ""
    pet_type = ""
    pet_age = 0

    pet_name = input('Enter the nme of the pet: ')
    pet_type = input('Enter the type of animal: ')
    pet_age = int(input('Enter the age of the pet: '))

    mypet = pet.Pet(pet_name, pet_type, pet_age)

    print('Here is the data that you entered: ')
    print('Pet name: ', mypet.get_name())
    print('Animal type: ', mypet.get_animal_type())
    print('Age of pet: ', mypet.get_age())
コード例 #11
0
ファイル: Use_pet_Class.py プロジェクト: lan33-ccac/CIT-119
def main():
    pet_name = ''
    pet_type = ''
    pet_age = ''

    mypet = pet.Pet(pet_name, pet_type, pet_age)

    pet_name = input("Enter your pet's name: ")
    pet_type = input("Enter your pet type: ")
    pet_age = input("Enter your pet's age: ")

    mypet.set_name(pet_name)
    mypet.set_animal_type(pet_type)
    mypet.set_age(pet_age)

    print("Your pet's name is", mypet.get_name(pet_name))
    print("Your pet's type is", mypet.get_animal_type(pet_type))
    print("Your pet's age is", mypet.get_age(pet_age))
コード例 #12
0
def main():

    #Ask user for pet's attributes
    pName = input("What is your pet's name?\t--> ")
    pType = input("What type of pet is this?\t--> ")
    pAge = input("What is your pet's age?\t\t--> ")

    #Create a Pet object
    petClass = pet.Pet(pName, pType, pAge)

    #Saves the inputs
    petClass.set_name(pName)
    petClass.set_animal_type(pType)
    petClass.set_age(pAge)

    #Outputs pet's attributes
    print("\nYour pet's name is:\t", petClass.get_name(), sep="")
    print("Your pet is a:\t\t", petClass.get_animal_type(), sep="")
    print("Your pet's age is:\t", petClass.get_age(), sep="")
コード例 #13
0
def main():
    # local varibles

    pet_name = ""
    pet_type = ""
    pet_age = ""

    # get pet data
    pet_name = input("Enter the name of the pet: ")
    pet_type = input("Enter the type of the pet: ")
    pet_age = int(input("Enter the age of the pet: "))

    # Create an insance of the pet class and assign it to an object
    mypet = pet.Pet(pet_name, pet_type, pet_age)


    # display the datat that was entered
    print("here is the data that you entered")
    print("pet name: ", mypet.get_name())
    print("pet type: ", mypet.get_animal_type())
    print("pet type: ", mypet.get_age())
コード例 #14
0
def main():

    name = input("Enter your pet's name: ")

    print(name)

    animal_type = input('Enter animal type: ')

    print(animal_type)

    age = float(input('Enter the age of your animal: '))

    print(age)

    #creating an object of pet clas
    my_Pet = pet.Pet(animal_type, age, name)

    print("Your pet's name is: ", my_Pet.get_name())

    print("The type of animal you have is: ", my_Pet.get_animal_type())

    print("Your pet's age:  ", my_Pet.get_age())
コード例 #15
0
ファイル: pet_info.py プロジェクト: CyberCrypter2810/CFPython
def main():
    # create a list for pet info
    animal = []

    # ask user how many pets they have
    num = int(input("How many pets do you have? "))

    # loop for creating data for pet class
    for var in range(1, num+1):
        name = input("What is the name of your " + str(var) + " pet? ")
        animal_type = input("What type of pet is it? ")
        age = int(input("How old is your pet? "))

        # sends data to pet class
        pets = pet.Pet(name, animal_type, age)

        # append the pet list
        animal.append(pets)

    # displays data from pet
    for item in animal:
        print()
        print(str(item))
コード例 #16
0
import pet

p1 = pet.pets[0]
p2 = pet.Pet("Polly", ["cracker", "scurvy dog"])

# print(p1.speak()) # you have to use a method for your object to *do* anything. in this case, speak()
# print(p2.speak())

pet.teach_random(p1, 2)
pet.teach_random(p2, 3)

# print(p1.speak())
# print(p2.speak())
コード例 #17
0
ファイル: pet_owner.py プロジェクト: barmi/CodingClub_python
# pet_owner.py
# 이 도전을 해결하는 방법은 여러가지가 있습니다. 이 방법은 그 중 하나입니다.

import pet

# 2개의 동물을 만듭니다.
romeo = pet.Pet("타란툴라")
juliet = pet.Pet("피라냐")

# 거미와 놀아줍니다.
romeo.eat()
romeo.sleep()

# 물고기와 놀아줍니다.
juliet.eat()
juliet.sleep()
コード例 #18
0
ファイル: __main__.py プロジェクト: nahaza/pythonTraining
def main():
    name = input("Enter your pet's name: ")
    animal_type = input("Enter animal_type: ")
    age = int(input("Enter your pet's age: "))
    my_pet = pet.Pet(name, animal_type, age)
    print(my_pet)
コード例 #19
0
import pet

# Get the pet's name, type, and age
name = input("What is your pet's name? ")
animal_type = input("What type of animal is that? ")
age = input("How old is your pet?")

# Create an instance of the Pet class.
my_pet = pet.Pet(name, animal_type, age)

print("Here is the information you entered:")
print("Pet name:", my_pet.get_name())
print("Animal type:", my_pet.get_animal_type())
print("Age:", my_pet.get_age())
コード例 #20
0
#!/usr/bin/env python3

import pet
if __name__ == "__main__":
    p = pet.Pet("Michael")
    print(p)
    if p.getName() != "Michael":
        print("Oops")
    else:
        print("Welcome, {}".format(p.getName()))
コード例 #21
0
def main():
    userChoice = 0
    while (userChoice != 4):
        userChoice = int(input("Enter a question to run: "))
        if (userChoice == 1):
            print("Enter information about your pet.")
            name = str(input("Enter its name: "))
            aType = str(input("Enter what type of animal it is: "))
            age = int(input("Enter its age: "))
            info = pet.Pet(name, aType, age)
            info.set_name()
            info.set_animal_type()
            info.set_age()
            print("name = ", info.get_name())
            print("type = ", info.get_animal_type())
            print("age = ", info.get_age())
        elif (userChoice == 2):
            print("This section will compare two energy values.")
            results = compare()
            print("Energy 1: ", format(results[0], '.2f'))
            print("Energy 2: ", format(results[1], '.2f'))
            print("Winner: ", results[2])
        elif (userChoice == 3):
            print("Let's play Rock, Paper, Scissors~!")
            gameplay = rockpaperscissor.RockPaperScissor()
            computerWins = 0
            userWins = 0
            ties = 0
            for n in range(1, 6):
                print("Game ", n, ":")
                user = str(
                    input(
                        "Pick your choice[type 'rock','paper', or 'scissors']: "
                    ))
                gameplay.set_rpsValue()
                computer = gameplay.get_rpsValue()
                print("Computer plays: ", computer)
                if (user == 'rock' and computer == 'paper'):
                    print("Computer wins this round!")
                    computerWins += 1
                elif (user == 'rock' and computer == 'scissors'):
                    print("You win this round!")
                    userWins += 1
                elif (user == 'paper' and computer == 'rock'):
                    print("You win this round!")
                    userWins += 1
                elif (user == 'paper' and computer == 'scissors'):
                    print("Computer wins this round!")
                    computerWins += 1
                elif (user == 'scissors' and computer == 'rock'):
                    print("Computer wins this round!")
                    computerWins += 1
                elif (user == 'scissors' and computer == 'paper'):
                    print("You win this round!")
                    userWins += 1
                elif (user == computer):
                    print("It's a tie!")
                    ties += 1
                else:
                    print("That is not a valid answer. Enter again.")
            print("Final Score")
            print("You: ", userWins)
            print("Computer: ", computerWins)
            print("Ties: ", ties)
            if (userWins > computerWins):
                print("You win!")
            elif (computerWins > userWins):
                print("Computer wins!")
            else:
                print("It's a tie!")
コード例 #22
0
ファイル: pet_test.py プロジェクト: 507-w20-instructors/dyu2
    def testSpeak(self):
        p1 = pet.pets[0]
        p2 = pet.Pet("Polly", ["cracker", "scurvy dog"])

        self.assertEqual(p1.speak(), "I can say hi bye")
        self.assertEqual(p2.speak(), "I can say cracker scurvy dog")
コード例 #23
0
# set_name (This method assigns a value to the __name field.)
# set_animal_type (This method assigns a value to the __animal_type field.)
# set_age (This method assigns a value to the __age field.)
# get_name (This method returns the value of the __name field.)
# get_animal_type (This method returns the value of the __animal_type field.)
# get_age (This method returns the value of the __age field.)
#
# Once you have written the class, write a program that creates an object of the class
# and prompts the user to enter the name, type, and age of his or her pet. This data
# should be stored as the object's attributes. Use the object's accessor methods to
# retrieve the pet's name, type, and age and display the data on the screen.

import pet

# Create an instance of the class.
my_pet = pet.Pet("", "", 0)

# Get pet data from user input.
name = input("What is your pet's name? ")
animal_type = input("What type of animal is that? ")
age = input("How old is your pet? ")

# Assign values based on input.
my_pet.set_name(name)
my_pet.set_animal_type(animal_type)
my_pet.set_age(age)

# Output the pet data.
print("Here is the information we have on file for your pet:")
print("Pet name:", my_pet.get_name())
print("Animal type:", my_pet.get_animal_type())
コード例 #24
0
ファイル: pet_test.py プロジェクト: 507-w20-instructors/dyu2
 def testConstructor(self):
     p1 = pet.Pet("fido")
     p2 = pet.Pet("rufus", ["bark", "woof"])
     self.assertEqual(p1.name, "fido")
     self.assertEqual(p2.name, "rufus")
     self.assertEqual(p2.words[0], "bark")