def main():
    num_of_samp = 10000
    for name in sys.argv[1:]:
        if not country_name_valid(name):
            print 'Invalid country name: ' + name
            return False
    if len(sys.argv[1:]) < 2:
        print 'Input country names must be more than one!'
        return False

    country_list = []
    for data in input_data.data_2018:
        ctry = Country(data[0], data[1], data[2])
        country_list.append(ctry)

    cup_2018 = Cup('World Cup 2018')
    valid = 0
    for i in range(0, num_of_samp):
        cup_2018.set_group_members(country_list, goupping_function_2018)
        if cup_2018.teams_in_same_group(sys.argv[1:]):
            valid += 1

    result = round(float(valid) / float(num_of_samp) * 100, 2)
    msg = []
    msg.append('The possibility of')
    msg.append(', '.join(sys.argv[1:]))
    msg.append('in the same group is')
    msg.append(str(result) + '%')
    print ' '.join(msg)
def worldcup_2018():
    country_list = []
    for data in input_data.data_2018:
        ctry = Country(data[0], data[1], data[2])
        country_list.append(ctry)
    cup_2018 = Cup('World Cup 2018')
    cup_2018.set_group_members(country_list, goupping_function_2018)
    print cup_2018.all
Beispiel #3
0
def main():
    '''Entry point'''
    print("Let's play a game!\n")
    dices = int(input("How many die? "))
    points = int(input("How many points? "))

    p1 = Player("Rafa", Cup(dices))
    p2 = Player("Mo", Cup(dices))

    print(game(p1, p2, dices, points))
Beispiel #4
0
def turn_input_into_cups(input_):
    """
    Creates a Cup for each number in input_ and returns a dict of all cups
    """
    cups = {a: Cup(a) for a in input_}
    max_number = len(cups)

    for cup, next_cup in zip(input_, input_[1:] + input_[:1]):
        cups[cup].next = cups[next_cup]

    for i in range(2, max_number + 1):
        cups[i].one_below = cups[i - 1]
    cups[1].one_below = cups[max_number]

    return cups
Beispiel #5
0
from cup import Cup, render_template

app = Cup()


@app.route('/')
def new_url(request):
    error = None
    url = ''
    if request.method == 'POST':
        url = request.form['url']
        short_id = url
        return redirect('/%s+' % short_id)
    return render_template("new_url.html")


@app.route('/<short_id>')
def follow_short_link(request, short_id):
    return "Damn"


@app.route('/<short_id>+')
def on_short_link_details(request, short_id):
    return "FOOO"


if __name__ == '__main__':
    app.run('127.0.0.1', 5000, app)
Beispiel #6
0
        with SMBus(I2C_BUS) as bus:
            #header = 0
            #while header != 0x12:
            #    header = bus.read_byte(SLAVE_ADDRESS)
            #count, adc, ball_detected = bus._read_bytes(SLAVE_ADDRESS, '<BHB')

            for cup in cups:
                cup_status = cup.get_status(bus)

                if cup_status.header != 0x12:
                    print('ERR')
                    continue

                print('#%d -> ADC = %d %s' %
                      (cup_status.count, cup_status.adc,
                       'YES' if cup_status.ball_detected == 1 else
                       cup_status.ball_detected))


if __name__ == '__main__':

    cup0 = Cup(SLAVE_ADDRESS)
    cups = [cup0]

    ball_detection_thread = threading.Thread(target=print_i2c_data,
                                             args=(cups, ),
                                             daemon=True)
    ball_detection_thread.start()

    a = input('Press enter to quit...')