Ejemplo n.º 1
0
def main():
    bornBefore = Date(6, 1, 1988)
    bag = Bag()

    # Extract dates from the user and place them in the bag.
    date = promptAndExtractDate()
    while date is not None:
        bag.add(date)
        date = promptAndExtractDate()
        # Iterate over the bag and check the age.

        for date in bag:
            if date <= bornBefore:
                print("Is at least 21 years of age: ", date)
Ejemplo n.º 2
0
def main():
    # Date before which a person must have been born to be 21 or older
    bornBefore = Date(6, 1, 1988)
    bag = Bag()
    # Extract dates from the user and place them in the bag

    date = promptAndExtractDate()
    while date is not None:
        bag.add(date)
        date = promptAndExtractDate()

    # Checks those items less than 21 years
    for date in bag:
        if date <= bornBefore:
            print("Is at least 21 years of age")
def main():
    bornBefore = Date(6, 1, 1988)
    bag = Bag()

    date = promptAndExtractDate()
    while date is not None:
        print(date)
        bag.add(date)
        date = promptAndExtractDate()

    for date in bag:
        if date <= bornBefore:
            print("Is at least 21 years of age: ", date)
        else:
            print(date)
Ejemplo n.º 4
0
def main():
		# Date before which a person must have been born to be 21 or older.
		bornBefore = date(1995, 06, 27)
		bag = Bag()
		
		# Extract birth dates from the user and determine if 21 or older.
		date_input = promptAndExtractDate()
		while date_input is not None:
			bag.add(date_input)
			date_input = promptAndExtractDate()
			
		# Iterate over the bag and check the age.
		for date1 in bag:
			if date1 <= bornbefore :
				print('Is at least 21 years of age: ', date1)
def main():
    a =5
    print(type(a))
    # Date before which a person must have been born to be 21 or older.
    bornBefore = date(1988, 1, 6)
    bag1 = Bag()
    
    # Extract birth dates from the user and determine if 21 or older.
    date1 = promptAndExtractDate()
    # print date1
    # print type(date1)
    while date1 is not None :
        bag1.add(date1)
        date1 = promptAndExtractDate()
        
    #print type(bag1)
    print(bag1.__len__())
    
    
    for date1 in bag1:
        if date1<=bornBefore:
            print("Is at least 21 years of age: ", date1)
Ejemplo n.º 6
0
from linearbag import Bag

if __name__ == "__main__":
    myBag = Bag()
    myBag.add("item1")
    myBag.add("item2")
    myBag.add("item3")
    # create a BagIterator object for myBag
    iterator = myBag.__iter__()

    # Repeat the while loop until break is called
    while True:
        try:
            # Get the next item from the bag. If there are no
            # more items , the StopIteration exception is raised
            item = iterator.__next__()
            # perform the body of the for loop
            print(item)
        # catch the exception and break from the loop when we are done.
        except StopIteration:
            break


Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
# File: bagtest1.py
# From: Data Structures and Algorithms Using Python.pdf, page 16

# Jedi: It is mean from file import class name.
from linearbag import Bag

myBag = Bag()
myBag.add(19)
myBag.add(74)
myBag.add(23)
myBag.add(23)
myBag.add(19)
myBag.add(12)

value = int(input("Guess a value contained in the bag. "))
if value in myBag:
    print "The bag contains the value", value
else:
    print "The bag does not contain the value", value
Ejemplo n.º 8
0
from linearbag import Bag

myBag = Bag()
myBag.add(12)
myBag.add(53)
myBag.add(95)
myBag.add(62)
myBag.add(19)
myBag.add(30)

value = int(input("Guess a value contained in the bag to list all the values in the bag: "))
if value in myBag:
    print("The bag contains the value", value)
    passed = True
    print("Here's a list of all the items in the bag")
else:
    print("The bag does not contain the value", value)
    passed = False
    print("I can't show you what's in the bag")

# Create a BagIterator object for myBag.
iterator = myBag.__iter__()

# Repeat the while loop until break is called.
while passed:
    try:
        # Get the next item from the bag. If there are no
        # more items, the StopIteration exception is raised.
        item = iterator.__next__()
        # Perform the body of the for loop.
        print(item)