rel=""> 10
+print(musician)
11
+
12
+musician = get_formatted_name('john', 'hooker', 'lee')
13
+print(musician)

+ 8 - 0
chapter_08/greet_users.py

@@ -0,0 +1,8 @@
1
+def greet_users(names):
2
+    """Print a simple greeting to each user in the list."""
3
+    for name in names:
4
+        msg = "Hello, " + name.title() + "!"
5
+        print(msg)
6
+
7
+usernames = ['hannah', 'ty', 'margot']
8
+greet_users(usernames)

+ 5 - 0
chapter_08/greeter.py

@@ -0,0 +1,5 @@
1
+def greet_user(username):
2
+    """Display a simple greeting."""
3
+    print("Hello, " + username.title() + "!")
4
+    
5
+greet_user('jesse')

+ 4 - 0
chapter_08/making_pizzas.py

@@ -0,0 +1,4 @@
1
+import pizza as p
2
+
3
+p.make_pizza(16, 'pepperoni')
4
+p.make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese')

+ 9 - 0
chapter_08/person.py

@@ -0,0 +1,9 @@
1
+def build_person(first_name, last_name, age=''):
2
+    """Return a dictionary of information about a person."""
3
+    person = {'first': first_name, 'last': last_name}
4
+    if age:
5
+        person['age'] = age
6
+    return person
7
+
8
+musician = build_person('jimi', 'hendrix', age=27)
9
+print(musician)

+ 13 - 0
chapter_08/pets.py

@@ -0,0 +1,13 @@
1
+def describe_pet(pet_name, animal_type='dog'):
2
+    """Display information about a pet."""
3
+    print("\nI have a " + animal_type + ".")
4
+    print("My " + animal_type + "'s name is " + pet_name.title() + ".")
5
+    
6
+# A dog named Willie.
7
+describe_pet('willie')
8
+describe_pet(pet_name='willie')
9
+
10
+# A hamster named Harry.
11
+describe_pet('harry', 'hamster')
12
+describe_pet(pet_name='harry', animal_type='hamster')
13
+describe_pet(animal_type='hamster', pet_name='harry')

+ 9 - 0
chapter_08/pizza.py

@@ -0,0 +1,9 @@
1
+def make_pizza(size, *toppings):
2
+    """Summarize the pizza we are about to make."""
3
+    print("\nMaking a " + str(size) +
4
+          "-inch pizza with the following toppings:")
5
+    for topping in toppings:
6
+        print("- " + topping)
7
+        
8
+make_pizza(16, 'pepperoni')
9
+make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese')

+ 24 - 0
chapter_08/printing_models.py

@@ -0,0 +1,24 @@
1
+def print_models(unprinted_designs, completed_models):
2
+    """
3
+    Simulate printing each design, until there are none left.
4
+    Move each design to completed_models after printing.
5
+    """
6
+    while unprinted_designs:
7
+        current_design = unprinted_designs.pop()
8
+    
9
+        # Simulate creating a 3d print from the design.
10
+        print("Printing model: " + current_design)
11
+        completed_models.append(current_design)
12
+        
13
+def show_completed_models(completed_models):
14
+    """Show all the models that were printed."""
15
+    print("\nThe following models have been printed:")
16
+    for completed_model in completed_models:
17
+        print(completed_model)
18
+        
19
+        
20
+unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
21
+completed_models = []
22
+
23
+print_models(unprinted_designs, completed_models)
24
+show_completed_models(completed_models)

+ 13 - 0
chapter_08/user_profile.py

@@ -0,0 +1,13 @@
1
+def build_profile(first, last, **user_info):
2
+    """Build a dictionary containing everything we know about a user."""
3
+    profile = {}
4
+    profile['first_name'] = first
5
+    profile['last_name'] = last
6
+    for key, value in user_info.items():
7
+        profile[key] = value
8
+    return profile
9
+
10
+user_profile = build_profile('albert', 'einstein',
11
+                             location='princeton',
12
+                             field='physics')
13
+print(user_profile)

+ 34 - 0
chapter_09/car.py

@@ -0,0 +1,34 @@
1
+"""A class that can be used to represent a car."""
2
+
3
+class Car():
4
+    """A simple attempt to represent a car."""
5
+
6
+    def __init__(self, manufacturer, model, year):
7
+        """Initialize attributes to describe a car."""
8
+        self.manufacturer = manufacturer
9
+        self.model = model
10
+        self.year = year
11
+        self.odometer_reading = 0
12
+        
13
+    def get_descriptive_name(self):
14
+        """Return a neatly formatted descriptive name."""
15
+        long_name = str(self.year) + ' ' + self.manufacturer + ' ' + self.model
16
+        return long_name.title()
17
+    
18
+    def read_odometer(self):
19
+        """Print a statement showing the car's mileage."""
20
+        print("This car has " + str(self.odometer_reading) + " miles on it.")
21
+        
22
+    def update_odometer(self, mileage):
23
+        """
24
+        Set the odometer reading to the given value.
25
+        Reject the change if it attempts to roll the odometer back.
26
+        """
27
+        if mileage >= self.odometer_reading:
28
+            self.odometer_reading = mileage
29
+        else:
30
+            print("You can't roll back an odometer!")
31
+    
32
+    def increment_odometer(self, miles):
33
+        """Add the given amount to the odometer reading."""
34
+        self.odometer_reading += miles

+ 27 - 0
chapter_09/dog.py

@@ -0,0 +1,27 @@
1
+class Dog():
2
+    """A simple attempt to model a dog."""
3
+    
4
+    def __init__(self, name, age):
5
+        """Initialize name and age attributes."""
6
+        self.name = name
7
+        self.age = age
8
+        
9
+    def sit(self):
10
+        """Simulate a dog sitting in response to a command."""
11
+        print(self.name.title() + " is now sitting.")
12
+
13
+    def roll_over(self):
14
+        """Simulate rolling over in response to a command."""
15
+        print(self.name.title() + " rolled over!")
16
+        
17
+
18
+my_dog = Dog('willie', 6)
19
+your_dog = Dog('lucy', 3)
20
+
21
+print("My dog's name is " + my_dog.name.title() + ".")
22
+print("My dog is " + str(my_dog.age) + " years old.")
23
+my_dog.sit()
24
+
25
+print("\nMy dog's name is " + your_dog.name.title() + ".")
26
+print("My dog is " + str(your_dog.age) + " years old.")
27
+your_dog.sit()

+ 37 - 0
chapter_09/electric_car.py

@@ -0,0 +1,37 @@
1
+"""A set of classes that can be used to represent electric cars."""
2
+
3
+from car import Car
4
+
5
+class Battery():
6
+    """A simple attempt to model a battery for an electric car."""
7
+
8
+    def __init__(self, battery_size=60):
9
+        """Initialize the batteery's attributes."""
10
+        self.battery_size = battery_size
11
+
12
+    def describe_battery(self):
13
+        """Print a statement describing the battery size."""
14
+        print("This car has a " + str(self.battery_size) + "-kWh battery.")  
15
+        
16
+    def get_range(self):
17
+        """Print a statement about the range this battery provides."""
18
+        if self.battery_size == 60:
19
+            range = 140
20
+        elif self.battery_size == 85:
21
+            range = 185
22
+            
23
+        message = "This car can go approximately " + str(range)
24
+        message += " miles on a full charge."
25
+        print(message)
26
+    
27
+        
28
+class ElectricCar(Car):
29
+    """Models aspects of a car, specific to electric vehicles."""
30
+
31
+    def __init__(self, manufacturer, model, year):
32
+        """
33
+        Initialize attributes of the parent class.
34
+        Then initialize attributes specific to an electric car.
35
+        """
36
+        super().__init__(manufacturer, model, year)
37
+        self.battery = Battery()

+ 12 - 0
chapter_09/favorite_languages.py

@@ -0,0 +1,12 @@
1
+from collections import OrderedDict
2
+
3
+favorite_languages = OrderedDict()
4
+
5
+favorite_languages['jen'] = 'python'
6
+favorite_languages['sarah'] = 'c'
7
+favorite_languages['edward'] = 'ruby'
8
+favorite_languages['phil'] = 'python'
9
+
10
+for name, language in favorite_languages.items():
11
+    print(name.title() + "'s favorite language is " +
12
+        language.title() + ".")

+ 7 - 0
chapter_09/my_car.py

@@ -0,0 +1,7 @@
1
+from car import Car
2
+
3
+my_new_car = Car('audi', 'a4', 2015)
4
+print(my_new_car.get_descriptive_name())
5
+
6
+my_new_car.odometer_reading = 23
7
+my_new_car.read_odometer()

+ 8 - 0
chapter_09/my_cars.py

@@ -0,0 +1,8 @@
1
+from car import Car
2
+from electric_car import ElectricCar
3
+
4
+my_beetle = Car('volkswagen', 'beetle', 2015)
5
+print(my_beetle.get_descriptive_name())
6
+
7
+my_tesla = ElectricCar('tesla', 'roadster', 2015)
8
+print(my_tesla.get_descriptive_name())

+ 13 - 0
chapter_10/alice.py

@@ -0,0 +1,13 @@
1
+filename = 'alice.txt'
2
+
3
+try:
4
+    with open(filename, encoding='utf-8') as f_obj:
5
+        contents = f_obj.read()
6
+except FileNotFoundError as e:
7
+    msg = "Sorry, the file " + filename + " does not exist."
8
+    print(msg)
9
+else:
10
+    # Count the approximate number of words in the file.
11
+    words = contents.split()
12
+    num_words = len(words)
13
+    print("The file " + filename + " has about " + str(num_words) + " words.")

File diff suppressed because it is too large
+ 3735 - 0
chapter_10/alice.txt


+ 14 - 0
chapter_10/division.py

@@ -0,0 +1,14 @@
1
+print("Give me two numbers, and I'll divide them.")
2
+print("Enter 'q' to quit.")
3
+
4
+while True:
5
+    first_number = input("\nFirst number: ")
6
+    if first_number == 'q':
7
+        break
8
+    second_number = input("Second number: ")
9
+    try:
10
+        answer = int(first_number) / int(second_number)
11
+    except ZeroDivisionError:
12
+        print("You can't divide by 0!")
13
+    else:
14
+        print(answer)

+ 7 - 0
chapter_10/file_reader.py

@@ -0,0 +1,7 @@
1
+filename = 'pi_digits.txt'
2
+
3
+with open(filename) as file_object:
4
+    lines = file_object.readlines()
5
+
6
+for line in lines:
7
+    print(line.rstrip())

+ 7 - 0
chapter_10/greet_user.py

@@ -0,0 +1,7 @@
1
+import json
2
+
3
+filename = 'username.json'
4
+
5
+with open(filename) as f_obj:
6
+    username = json.load(f_obj)
7
+    print("Welcome back, " + username + "!")

File diff suppressed because it is too large
+ 21022 - 0
chapter_10/little_women.txt


File diff suppressed because it is too large
+ 22108 - 0
chapter_10/moby_dick.txt


+ 7 - 0
chapter_10/number_reader.py

@@ -0,0 +1,7 @@
1
+import json
2
+
3
+filename = 'numbers.json'
4
+with open(filename) as file_object:
5
+    numbers = json.load(file_object)
6
+    
7
+print(numbers)

+ 7 - 0
chapter_10/number_writer.py

@@ -0,0 +1,7 @@
1
+import json
2
+
3
+numbers = [2, 3, 5, 7, 11, 13]
4
+
5
+filename = 'numbers.json'
6
+with open(filename, 'w') as file_object:
7
+    json.dump(numbers, file_object)

+ 1 - 0
chapter_10/numbers.json

@@ -0,0 +1 @@
1
+[2, 3, 5, 7, 11, 13]

+ 3 - 0
chapter_10/pi_30_digits.txt

@@ -0,0 +1,3 @@
1
+3.1415926535
2
+  8979323846
3
+  2643383279

+ 3 - 0
chapter_10/pi_digits.txt

@@ -0,0 +1,3 @@
1
+3.1415926535
2
+  8979323846
3
+  2643383279

File diff suppressed because it is too large
+ 10000 - 0
chapter_10/pi_million_digits.txt


+ 14 - 0
chapter_10/pi_string.py

@@ -0,0 +1,14 @@
1
+filename = 'pi_million_digits.txt'
2
+
3
+with open(filename) as file_object:
4
+    lines = file_object.readlines()
5
+
6
+pi_string = ''
7
+for line in lines:
8
+    pi_string += line.rstrip()
9
+
10
+birthday = input("Enter your birthday, in the form mmddyy: ")
11
+if birthday in pi_string:
12
+    print("Your birthday appears in the first million digits of pi!")
13
+else:
14
+    print("Your birthday does not appear in the first million digits of pi.")

+ 4 - 0
chapter_10/programming.txt

@@ -0,0 +1,4 @@
1
+I love programming.
2
+I love creating new games.
3
+I also love finding meaning in large datasets.
4
+I love creating apps that can run in a browser.

+ 31 - 0
chapter_10/remember_me.py

@@ -0,0 +1,31 @@
1
+import json
2
+
3
+def get_stored_username():
4
+    """Get stored username if available."""
5
+    filename = 'username.json'
6
+    try:
7
+        with open(filename) as f_obj:
8
+            username = json.load(f_obj)
9
+    except FileNotFoundError:
10
+        return None
11
+    else:
12
+        return username
13
+
14
+def get_new_username():
15
+    """Prompt for a new username."""
16
+    username = input("What is your name? ")
17
+    filename = 'username.json'
18
+    with open(filename, 'w') as f_obj:
19
+        json.dump(username, f_obj)
20
+    return username
21
+
22
+def greet_user():
23
+    """Greet the user by name."""
24
+    username = get_stored_username()
25
+    if username:
26
+        print("Welcome back, " + username + "!")
27
+    else:
28
+        username = get_new_username()
29
+        print("We'll remember you when you come back, " + username + "!")
30
+
31
+greet_user()

File diff suppressed because it is too large
+ 4319 - 0
chapter_10/siddhartha.txt


+ 16 - 0
chapter_10/word_count.py

@@ -0,0 +1,16 @@
1
+def count_words(filename):
2
+    """Count the approximate number of words in a file."""
3
+    try:
4
+        with open(filename, encoding='utf-8') as f_obj:
5
+            contents = f_obj.read() 
6
+    except FileNotFoundError:
7
+        pass
8
+    else:
9
+        # Count approximate number of words in the file.
10
+        words = contents.split()
11
+        num_words = len(words)
12
+        print("The file " + filename + " has about " + str(num_words) + " words.")
13
+
14
+filenames = ['alice.txt', 'siddhartha.txt', 'moby_dick.txt', 'little_women.txt']
15
+for filename in filenames:
16
+    count_words(filename)

+ 5 - 0
chapter_10/write_message.py

@@ -0,0 +1,5 @@
1
+filename = 'programming.txt'
2
+
3
+with open(filename, 'a') as file_object:
4
+    file_object.write("I also love finding meaning in large datasets.\n")
5
+    file_object.write("I love creating apps that can run in a browser.\n")

+ 18 - 0
chapter_11/language_survey.py

@@ -0,0 +1,18 @@
1
+from survey import AnonymousSurvey
2
+
3
+# Define a question, and make a survey object.
4
+question = "What language did you first learn to speak?"
5
+my_survey = AnonymousSurvey(question)
6
+
7
+# Show the question, and store responses to the question.
8
+my_survey.show_question()
9
+print("Enter 'q' at any time to quit.\n")
10
+while True:
11
+    response = input("Language: ")
12
+    if response == 'q':
13
+        break
14
+    my_survey.store_response(response)
15
+
16
+# Show the survey results.
17
+print("\nThank you to everyone who participated in the survey!")
18
+my_survey.show_results()

+ 7 - 0
chapter_11/name_function.py

@@ -0,0 +1,7 @@
1
+def get_formatted_name(first, last, middle=''):
2
+    """Generate a neatly-formatted full name."""
3
+    if middle:
4
+        full_name = first + ' ' + middle + ' ' + last
5
+    else:
6
+        full_name = first + ' ' + last
7
+    return full_name.title()

+ 14 - 0
chapter_11/names.py

@@ -0,0 +1,14 @@
1
+from name_function import get_formatted_name
2
+
3
+print("Enter 'q' at any time to quit.")
4
+while True:
5
+    first = input("\nPlease give me a first name: ")
6
+    if first == 'q':
7
+        break
8
+        
9
+    last = input("Please give me a last name: ")
10
+    if last == 'q':
11
+        break
12
+        
13
+    formatted_name = get_formatted_name(first, last)
14
+    print("\tNeatly formatted name: " + formatted_name + '.')

+ 21 - 0
chapter_11/survey.py

@@ -0,0 +1,21 @@
1
+class AnonymousSurvey():
2
+    """Collect anonymous answers to a survey question."""
3
+    
4
+    def __init__(self, question):
5
+        """Store a question, and prepare to store responses."""
6
+        self.question = question
7
+        self.responses = []
8
+        
9
+    def show_question(self):
10
+        """Show the survey question."""
11
+        print(self.question)
12
+        
13
+    def store_response(self, new_response):
14
+        """Store a single response to the survey."""
15
+        self.responses.append(new_response)
16
+        
17
+    def show_results(self):
18
+        """Show all the responses that have been given."""
19
+        print("Survey results:")
20
+        for response in self.responses:
21
+            print('- ' + response)

+ 17 - 0
chapter_11/test_name_function.py

@@ -0,0 +1,17 @@
1
+import unittest
2
+from name_function import get_formatted_name
3
+
4
+class NamesTestCase(unittest.TestCase):
5
+    """Tests for 'name_function.py'."""
6
+    
7
+    def test_first_last_name(self):
8
+        formatted_name = get_formatted_name('janis', 'joplin')
9
+        self.assertEqual(formatted_name, 'Janis Joplin')
10
+        
11
+    def test_first_last_middle_name(self):
12
+        formatted_name = get_formatted_name(
13
+            'wolfgang', 'mozart', 'amadeus')
14
+        self.assertEqual(formatted_name, 'Wolfgang Amadeus Mozart')
15
+            
16
+
17
+unittest.main()

+ 30 - 0
chapter_11/test_survey.py

@@ -0,0 +1,30 @@
1
+import unittest
2
+from survey import AnonymousSurvey
3
+
4
+class TestAnonymousSurvey(unittest.TestCase):
5
+    """Tests for the class AnonymousSurvey."""
6
+    
7
+    def setUp(self):
8
+        """
9
+        Create a survey and a set of responses for use in all test methods.
10
+        """
11
+        question = "What language did you first learn to speak?"
12
+        self.my_survey = AnonymousSurvey(question)
13
+        self.responses = ['English', 'Spanish', 'Mandarin']
14
+        
15
+    
16
+    def test_store_single_response(self):
17
+        """Test that a single response is stored properly."""
18
+        self.my_survey.store_response(self.responses[0])
19
+        self.assertIn(self.responses[0], self.my_survey.responses)
20
+        
21
+        
22
+    def test_store_three_responses(self):
23
+        """Test that three individual responses are stored properly."""
24
+        for response in self.responses:
25
+            self.my_survey.store_response(response)
26
+        for response in self.responses:
27
+            self.assertIn(response, self.my_survey.responses)
28
+            
29
+
30
+unittest.main()

File diff suppressed because it is too large
+ 114 - 0
chapter_12/README.md


+ 31 - 0
chapter_12/alien_invasion.py

@@ -0,0 +1,31 @@
1
+import pygame
2
+from pygame.sprite import Group
3
+
4
+from settings import Settings
5
+from ship import Ship
6
+import game_functions as gf
7
+
8
+def run_game():
9
+    # Initialize pygame, settings, and screen object.
10
+    pygame.init()
11
+    ai_settings = Settings()
12
+    screen = pygame.display.set_mode(
13
+        (ai_settings.screen_width, ai_settings.screen_height))
14
+    pygame.display.set_caption("Alien Invasion")
15
+    
16
+    # Set the background color.
17
+    bg_color = (230, 230, 230)
18
+    
19
+    # Make a ship.
20
+    ship = Ship(ai_settings, screen)
21
+    # Make a group to store bullets in.
22
+    bullets = Group()
23
+
24
+    # Start the main loop for the game.
25
+    while True:
26
+        gf.check_events(ai_settings, screen, ship, bullets)
27
+        ship.update()
28
+        gf.update_bullets(bullets)
29
+        gf.update_screen(ai_settings, screen, ship, bullets)
30
+
31
+run_game()

+ 0 - 0
chapter_12/bullet.py


Some files were not shown because too many files changed in this diff

tum/network_report_server - Gogs: Simplico Git Service

Açıklama Yok

tum 30f7226d9a first commit 2 yıl önce
..
LICENSE 30f7226d9a first commit 2 yıl önce
README.md 30f7226d9a first commit 2 yıl önce
package.json 30f7226d9a first commit 2 yıl önce

README.md

cheerio-select NPM version Build Status Downloads Coverage

CSS selector engine supporting jQuery selectors, based on css-select.

Supports all jQuery positional pseudo-selectors:

  • :first
  • :last
  • :eq
  • :nth
  • :gt
  • :lt
  • :even
  • :odd
  • :not(:positional), where :positional is any of the above.

This library is a thin wrapper around css-select. Only use this module if you will actually use jQuery positional selectors.