跳至主要內容
NYU – Tandon School of Engineering CS-UY 1114 Final Review

The Story

Professor and Pokémon trainer Katz wants to be the very best that no one ever was. To that end, he has travelled across the land and caught and trained a bunch of Eevees , which have now evolved. His team looks like this at the moment:


AI悦创原创...大约 4 分钟NYUNYU – Tandon School of EngineeringNYUNYU – Tandon School of Engineering
NYU – Tandon School of Engineering True Exam – 16 December 2021
  1. Evaluate this code. What will be printed
class Animal:
    def __init__(self, name, species, age):
        self.name = name
        self.species = species
        self.age = age

    def is_adult(self):
        return self.age > 3

    def is_young(self):
        return self.age < 1

    def __str__(self):
        return "{} ({}, {} years old)".format(self.name, self.species, self.age)

    def __repr__(self):
        return "Animal('{}', '{}', {})".format(self.name, self.species, self.age)

def main():
    cat = Animal("Fluffy", "cat", 2)
    dog = Animal("Rover", "dog", 4)
    bird = Animal("Tweety", "bird", 1)
    fish = Animal("Nemo", "fish", 0.5)

    a = cat.is_adult()
    b = dog.is_young()
    c = repr(bird)
    d = str(fish)
    e = fish.is_adult()
    f = bird.name

    print('It is', b, bird.name, "is young")
    print(b)
    print(c)
    print(bird)
    print(d)
    print(e)
    print(f)

AI悦创原创...大约 3 分钟NYUNYU – Tandon School of EngineeringNYUNYU – Tandon School of Engineering
NYU – Tandon School of Engineering Final Exam – 16 December 2021

Final Exam – 16 December 2021

  1. (15 Points) Provide the value of the variable “var” (use python form to show the appropriate data type, e.g. “str” , [list], etc). Note: following code snippets will not produce errors.

Value of var after code runs


AI悦创原创...大约 13 分钟NYUNYU – Tandon School of EngineeringNYUNYU – Tandon School of Engineering