Пример #1
0
def gameLoop(currentRoom=map['cell']):

    userInput = stdio.readString()

    if userInput in currentRoom['actions']:
        currentRoom = map[currentRoom['actions'][userInput]]

        if userInput == 'door' and player['Holding'] == 'key':
            stdio.writeln('\n' + door_exam['desc2'])
            battleLoop()

        if currentRoom == 'bone_take':
            bone_take['taken'] = True

    else:
        stdio.writeln()
        stdio.writeln('Sorry, that\'s not a valid input. Try Again.\n')
        stdio.write(PROMPT)
        gameLoop(currentRoom)

    if bone_take['taken'] == True:
        player['weapon'] = 'bone'

    stdio.writeln()
    keyCheck(currentRoom)
    stdio.writeln(currentRoom['desc'])
    stdio.writeln()
    actionList(currentRoom)
    stdio.writeln()
    stdio.write(PROMPT)

    gameLoop(currentRoom)
Пример #2
0
def actionList(currentRoom=map['cell']):

    stdio.writeln('What would you like to do? Here are your options:\n')
    for item in currentRoom['actions']:
        stdio.write(str(item) + ' ' + '/' + ' ')

    stdio.writeln()
Пример #3
0
def _main():
    a = stdarray.readFloat2D()
    c = transpose(a)
    for row in c:
        for v in row[:-1]:
            stdio.write(str(v) + ' ')
        stdio.writeln(row[-1])
Пример #4
0
def ex1_3_12():
    print()
    f = 0
    g = 1
    for i in range(16):
        stdio.write(str(f) + ' ')
        f = f + g
        g = f - g
Пример #5
0
def main():

    stdio.writeln()
    stdio.writeln(cell['desc'])
    stdio.writeln()
    stdio.writeln('yes / no\n')
    stdio.write(PROMPT)
    gameLoop()
Пример #6
0
def search(lo, hi):
    if (hi - lo) == 1:
        return lo
    mid = (hi + lo) // 2
    stdio.write("Greater than or equal to " + str(mid) + "?  ")
    if stdio.readBool():
        return search(mid, hi)
    else:
        return search(lo, mid)
def writeHad(h):
    n = len(h)
    for i in range(n):
        for j in range(n):
            if h[i][j]:
                stdio.write('T ')
            else:
                stdio.write('F ')
        stdio.writeln()
Пример #8
0
def search(lo, hi):
    if (hi - lo) == 1:
        return lo
    mid = (hi + lo) // 2
    stdio.write('Greater than or equal to ' + str(mid) + '?  ')
    if stdio.readBool():
        return search(mid, hi)
    else:
        return search(lo, mid)
Пример #9
0
def main():
    stack = Stack()
    while not stdio.isEmpty():
        item = stdio.readString()
        if item != '-':
            stack.push(item)
        else:
            stdio.write(stack.pop() + ' ')
    stdio.writeln()
def main():
    stack = Stack()
    while not stdio.isEmpty():
        item = stdio.readString()
        if item != '-':
            stack.push(item)
        else:
            stdio.write(stack.pop() + ' ')
    stdio.writeln()
def main():
    queue = Queue()
    while not stdio.isEmpty():
        item = stdio.readString()
        if item != '-':
            queue.enqueue(item)
        else:
            stdio.write(queue.dequeue())
            stdio.write(' ')
    stdio.writeln()
Пример #12
0
def main():
    queue = Queue()
    while not stdio.isEmpty():
        item = stdio.readString()
        if item != '-':
            queue.enqueue(item)
        else:
            stdio.write(queue.dequeue())
            stdio.write(' ')
    stdio.writeln()
Пример #13
0
def square(cols, rows, sym1):
    '''
    Draws pattern in square form. Add a space to your sym parameter.
    Cols and Rows are int, sym must be string.
    '''
    for i in range(1, cols + 1):
        for j in range(1, rows + 1):
            if i > 0:
                stdio.write(sym1)
        stdio.writeln()
Пример #14
0
def print_unique_factors(n):
    factor = 2
    while factor <= n // factor:
        if n % factor == 0:
            stdio.write(str(factor) + ' ')
            while n % factor == 0:
                n //= factor
        factor += 1
    if n > 1:
        stdio.write(n)
    print()
Пример #15
0
def opp_triang(cols, sym):
    """
    Prints an upside down right triangle.
    Cols is an int, sym must be string.
    """
    for i in range(2, cols + 2):
        for j in range(cols + 1, 0, -1):
            if j / i != 0:
                stdio.write(sym)
            stdio.write(' ')
        stdio.writeln()
Пример #16
0
def triang(cols, sym):
    '''
    Prints pattern in increasing order, shape of right triangle.
    Cols is an int, sym must be string.
    '''
    for i in range(1, cols + 1):
        for j in range(1, cols + 1):
            if i / j != 0:
                stdio.write(sym)
            stdio.write(' ')
        stdio.writeln()
Пример #17
0
def pyramid_down(cols, sym1):
    '''
    Prints upside down pyramid.
    Cols is an int, sym must be string.
    '''
    for i in range(1, cols + 1):
        for j in range(1, cols + 1):
            if j / i != 0:
                stdio.write(sym1)
            stdio.write(" ")
        stdio.writeln()
Пример #18
0
def main():
    instream = InStream('misspellings.txt')
    lines = instream.readAllLines()
    misspellings = SymbolTable()
    for line in lines:
        tokens = line.split(' ')
        misspellings[tokens[0]] = tokens[1]
    while not stdio.isEmpty():
        word = stdio.readString()
        if word in misspellings:
            stdio.write(word + '-->' + misspellings[word])
Пример #19
0
def write1D(a):
    """
    Write array 'a' to sys.stdout.  First write its length.
    """
    length = len(a)
    stdio.writeln(length)
    for i in range(length):
        # stdio.writef('%9.5f ', a[i])
        stdio.write(a[i])
        stdio.write(' ')
    stdio.writeln()
Пример #20
0
def relatively_prime(n):
    stdio.write('  ')
    for i in range(n):
        print('%2d' % (i + 1), end='')
    print()
    for i in range(n):
        print('%2d' % (i + 1), end='')
        for j in range(n):
            c = ' *' if greatest_common_divisor(i + 1, j + 1) == 1 else '  '
            print(c, end='')
        print()
Пример #21
0
def main():
    k = int(sys.argv[1])
    s = sys.argv[2]
    text = sys.stdin.read()
    model = MarkovModel(text, k)
    r = model.replace_unknown(s)
    for i in range(0, len(r)):
        if i == len(r) - 1:
            stdio.writeln(r[i])
        else:
            stdio.write(r[i])
Пример #22
0
def main():
    # v, s get from the commandline
    v, s = int(sys.argv[1]), sys.argv[2]
    t = sys.stdin.read()
    model = MarkovModel(t, v)
    r = model.replace_unknown(s)
    for i in range(0, len(r)):
        if i == len(r) - 1:
            stdio.writeln(r[i])
        else:
            stdio.write(r[i])
Пример #23
0
def write1D(a):
    """
    Write array 'a' to sys.stdout.  First write its length.
    """
    length = len(a)
    stdio.writeln(length)
    for i in range(length):
        # stdio.writef('%9.5f ', a[i])
        stdio.write(a[i])
        stdio.write(' ')
    stdio.writeln()
Пример #24
0
def print_converted_to_base(n, base):
    digits = '0123456789ABCDEF'
    power = 1
    while power <= (n // base):
        power *= base
    while power > 0:
        digit = n // power
        stdio.write(digits[digit])
        if digit > 0:
            n %= power
        power //= base
    stdio.writeln()
Пример #25
0
def side_triang(cols, sym, sym1):
    """
    --In progress, Prints a trianle shape to the right with space on the left.
    intended to be reflection of triang().
    """
    col = cols + 1
    for i in range(1, cols + 1):
        col -= 1
        for j in range(1, cols + 1):
            if i % j == 0:
                stdio.write(sym)
            stdio.write(sym1 * col)
        stdio.writeln()
Пример #26
0
def slant_barcode(cols, rows, sym, sym1):
    '''
    Creates a barcode that is in a slanted shape.
    Cols and rows are int, sym and sym1 must be string.
    '''
    if check(cols, rows):
        pass
    for i in range(1, cols + 1):
        for j in range(1, rows + 1):
            ran = random.randint(1, cols)
            if (i * j) % ran != 0:
                stdio.write(sym)
            stdio.write(sym1)
        stdio.writeln()
Пример #27
0
def write2D(a):
    """
    Write two-dimensional array 'a' to sys.stdout.  First write its
    dimensions.
    """
    rowCount = len(a)
    colCount = len(a[0])
    stdio.writeln(str(rowCount) + ' ' + str(colCount))
    for row in range(rowCount):
        for col in range(colCount):
            #stdio.writef('%9.5f ', a[row][col])
            stdio.write(a[row][col])
            stdio.write(' ')
        stdio.writeln()
Пример #28
0
def write2D(a):
    """
    Write two-dimensional array 'a' to sys.stdout.  First write its
    dimensions.
    """
    rowCount = len(a)
    colCount = len(a[0])
    stdio.writeln(str(rowCount) + ' ' + str(colCount))
    for row in range(rowCount):
        for col in range(colCount):
            #stdio.writef('%9.5f ', a[row][col])
            stdio.write(a[row][col])
            stdio.write(' ')
        stdio.writeln()
Пример #29
0
def keyCheck(currentRoom=map['cell']):

    if currentRoom == pillow_exam:
        if player['Holding'] == 'key':
            stdio.writeln('You\'ve already taken the key. ' +
                          'There is nothing else to take.')
            stdio.writeln()
            actionList(currentRoom)
            stdio.writeln()
            stdio.write(PROMPT)
            gameLoop(currentRoom)

    if currentRoom == pillow_exam:
        if player['Holding'] != 'key':
            player['Holding'] = 'key'
Пример #30
0
def main(argv):
    """
    For testing:
    """
    import stdio
    N = int(argv[1])
    t = [.5, .3, .1, .1]
    for i in range(N):
        stdio.writef(' %2d ', uniformInt(-100, 100))
        stdio.writef('%8.5f ', uniformFloat(10.0, 99.0))
        if bernoulli(.5):
            stdio.write('False ')
        else:
            stdio.write('True  ')
        stdio.writef('%7.5f ', gaussian(9.0, .2))
        stdio.writef('%2d ', discrete(t))
        stdio.writeln()
Пример #31
0
def main(argv):
    """
    For testing:
    """
    import stdio

    N = int(argv[1])
    t = [0.5, 0.3, 0.1, 0.1]
    for i in range(N):
        stdio.writef(" %2d ", uniformInt(-100, 100))
        stdio.writef("%8.5f ", uniformFloat(10.0, 99.0))
        if bernoulli(0.5):
            stdio.write("False ")
        else:
            stdio.write("True  ")
        stdio.writef("%7.5f ", gaussian(9.0, 0.2))
        stdio.writef("%2d ", discrete(t))
        stdio.writeln()
Пример #32
0
def write_1d(a):
    """
    Write array a to sys.stdout.  First write its length. bool objects are written as 0 and 1, not False and True.
    """
    length = len(a)
    stdio.writeln(length)
    for i in range(length):
        element = a[i]
        if isinstance(element, bool):
            if element:  # element == True
                stdio.write(1)
            else:
                stdio.write(0)
        else:
            stdio.write(element)
        stdio.write(' ')
    stdio.writeln()
Пример #33
0
def fibonacci():
	limit = int(input("How many numbers you want?"))
	a = 0
	b = 1
	stdio.write(str(a)+",")
	stdio.write(str(b)+",")
	for i in range(0 , limit):
		c = a + b
		stdio.write(str(c)+",")
		a = b
		b = c
	print()
Пример #34
0
def write1D(a):
    """
    Write array a to sys.stdout.  First write its length. bool objects
    are written as 0 and 1, not False and True.
    """
    length = len(a)
    stdio.writeln(length)
    for i in range(length):
        # stdio.writef('%9.5f ', a[i])
        element = a[i]
        if isinstance(element, bool):
            if element == True:
                stdio.write(1)
            else:
                stdio.write(0) 
        else:
            stdio.write(element)
        stdio.write(' ')
    stdio.writeln()
Пример #35
0
def write_2d(a):
    """
    Write two-dimensional array a to sys.stdout.  First write its dimensions. bool objects are written as 0 and 1, not
    False and True.
    """
    row_count = len(a)
    column_count = len(a[0])
    stdio.writeln(str(row_count) + ' ' + str(column_count))
    for row in range(row_count):
        for col in range(column_count):
            element = a[row][col]
            if isinstance(element, bool):
                if element:  # element == True
                    stdio.write(1)
                else:
                    stdio.write(0)
            else:
                stdio.write(element)
            stdio.write(' ')
        stdio.writeln()
Пример #36
0
def write2D(a):
    """
    Write two-dimensional array a to sys.stdout.  First write its
    dimensions. bool objects are written as 0 and 1, not False and True.
    """
    rowCount = len(a)
    colCount = len(a[0])
    stdio.writeln(str(rowCount) + ' ' + str(colCount))
    for row in range(rowCount):
        for col in range(colCount):
            #stdio.writef('%9.5f ', a[row][col])
            element = a[row][col]
            if isinstance(element, bool):
                if element == True:
                    stdio.write(1)
                else:
                    stdio.write(0)
            else:
                stdio.write(element)
            stdio.write(' ')
        stdio.writeln()
Пример #37
0
#-----------------------------------------------------------------------

import stdio
import sys

# Accept integer n as a command-line argument. Write to standard
# output the prime factors of n.

n = int(sys.argv[1])

factor = 2
while factor*factor <= n:
    while n % factor == 0:
        # Cast out and write factor.
        n //= factor
        stdio.write(str(factor) + ' ')
    factor += 1
    # Any factors of n are greater than or equal to factor.

if n > 1:
    stdio.write(n)
stdio.writeln()

#-----------------------------------------------------------------------

# python factors.py 3757208    
# 2 2 2 7 13 13 397

# python factors.py 287994837222311
# 17 1739347 9739789
Пример #38
0
import sys
import stdio

n = int(sys.argv[1])

v = 1
while v <= n // 2:
    v *= 2
    
while v > 0:
    if n < v:
        stdio.write(0)
    else:
        stdio.write(1)
        n -= v
    v //= 2
    
stdio.writeln()
Пример #39
0
# list from standard input, compute profiles based on k-gram
# frequencies for all the documents, and write a matrix of similarity
# measures between all pairs of documents. d is the dimension of the
# profiles.

k = int(sys.argv[1])
d = int(sys.argv[2])

filenames = stdio.readAllStrings()
sketches = stdarray.create1D(len(filenames))

for i in range(len(filenames)):
    text = InStream(filenames[i]).readAll()
    sketches[i] = Sketch(text, k, d)
    
stdio.write('    ')
for i in range(len(filenames)):
    stdio.writef('%8.4s', filenames[i])
stdio.writeln()

for i in range(len(filenames)):
    stdio.writef('%.4s', filenames[i])
    for j in range(len(filenames)):
        stdio.writef('%8.2f', sketches[i].similarTo(sketches[j]))
    stdio.writeln()
    
#-----------------------------------------------------------------------

# more documents.txt 
# constitution.txt
# tomsawyer.txt
Пример #40
0
for i in range(n):
    perm[i] = i

# Create random sample in perm[0], perm[1], ..., perm[m-1]
for i in range(m):

    # Choose a random integer r between i and n-1.
    r = random.randrange(i, n)

    # Swap perm[i] and perm[r].
    temp = perm[r]
    perm[r] = perm[i]
    perm[i] = temp

# Write the results.
for i in range(m):
    stdio.write(str(perm[i]) + ' ')
stdio.writeln()

#-----------------------------------------------------------------------

# python sample.py 6 16      
# 9 6 3 5 4 13

# python sample.py 10 1000
# 566 240 662 680 500 491 309 348 563 34 

# python sample.py 20 20  
# 15 6 19 5 1 4 10 16 7 3 13 14 12 2 9 0 18 8 17 11 

Пример #41
0
def main():
    a = stdio.readAllStrings()
    sort(a)
    for s in a:
        stdio.write(s + ' ')
    stdio.writeln()
Пример #42
0
words = stdio.readAllStrings()

bst = OrderedSymbolTable()

for i in range(len(words)):
    word = words[i]
    if len(word) >= minLength:
        if not word in bst:
            bst[word] = []
        bst[word] += [i]

for word in bst:
    occurrences = bst[word]
    if len(occurrences) >= minCount:
        stdio.write(word + ': ')
        for occurrence in occurrences:
            stdio.write(str(occurrence) + ' ')
        stdio.writeln()

#-----------------------------------------------------------------------

# python index.py 9 30 < tale.txt 
# confidence: 2794 23064 25031 34249 47907 48268 48577 ...
# courtyard: 11885 12062 17303 17451 32404 32522 38663 ...
# evremonde: 86211 90791 90798 90802 90814 90822 90856 ...
# expression: 3777 5575 6574 7116 7195 8509 8928 15015 ...
# gentleman: 2521 5290 5337 5698 6235 6301 6326 6338 ... 
# influence: 27809 36881 43141 43150 48308 54049 54067 ...
# monseigneur: 85 90 36587 36590 36611 36636 36643 36680 ...
# something: 3406 3765 9283 13234 13239 15245 20257 23642 ...
Пример #43
0
import sys
import stdio

stdio.write('Hi, ')
stdio.write(sys.argv[1])
stdio.writeln('.How are you?')
Пример #44
0
        return search(mid, hi)
    else:
        return search(lo, mid)


# -----------------------------------------------------------------------

# Accept integer command-line argument k. Ask the user to think of
# an integer between 0 and (2**k)-1. Write "Greater than or equal to?"
# questions to standard output, in binary search fashion. Read
# True/False replies from standard input. Write the integer to
# standard output.

k = int(sys.argv[1])
n = 2 ** k
stdio.write("Think of a number ")
stdio.writeln("between 0 and " + str(n - 1))
guess = search(0, n)
stdio.writeln("Your number is " + str(guess))

# -----------------------------------------------------------------------

# python questions.py 7
# Think of a number between 0 and 127
# Greater than or equal to 64?  True
# Greater than or equal to 96?  False
# Greater than or equal to 80?  False
# Greater than or equal to 72?  True
# Greater than or equal to 76?  True
# Greater than or equal to 78?  False
# Greater than or equal to 77?  True
Пример #45
0
#-----------------------------------------------------------------------
# useargument.py
#-----------------------------------------------------------------------

import stdio
import sys

# Accept a name as a command-line argument. Write a message containing
# that name to standard output.

stdio.write('Hi, ')
stdio.write(sys.argv[1])
stdio.writeln('. How are you?')

#-----------------------------------------------------------------------

# python useargument.py Alice
# Hi, Alice. How are you?

# python useargument.py Bob
# Hi, Bob. How are you?

# python useargument.py Carol
# Hi, Carol. How are you?
Пример #46
0
import sys
import stdio

stdio.write('Hi, ')
stdio.write(sys.argv[3])
stdio.write(', ')
stdio.write(sys.argv[2])
stdio.write(', and ')
stdio.write(sys.argv[1])
stdio.writeln('. How are you?')
Пример #47
0
#-----------------------------------------------------------------------
# twentyquestions.py
#-----------------------------------------------------------------------

import stdio
import random

# Generate a random integer. Repeatedly read user guesses from
# standard input. Write 'Too low' or 'Too high' to standard output,
# as appropriate, in response to each guess. Write 'You win!' to
# standard output and exit when the user's guess is correct.

RANGE = 1000000

secret = random.randrange(1, RANGE+1)
stdio.write('I am thinking of a secret number between 1 and ')
stdio.writeln(RANGE)
guess = 0
while guess != secret:
    # Solicit one guess and provide one answer.
    stdio.write('What is your guess? ')
    guess = stdio.readInt()
    if (guess < secret):
        stdio.writeln('Too low')
    elif (guess > secret):
        stdio.writeln('Too high')
    else:
        stdio.writeln('You win!')
        
#-----------------------------------------------------------------------
Пример #48
0
#-----------------------------------------------------------------------
# rangefilter.py
#-----------------------------------------------------------------------

import stdio
import sys

# Accept integer command-line arguments lo and hi. Read integers from
# standard input until end-of-file. Write to standard output each of
# those integers that is in the range lo to hi, inclusive.

lo = int(sys.argv[1])
hi = int(sys.argv[2])
while not stdio.isEmpty():
    # Process one integer.
    value = stdio.readInt()
    if (value >= lo) and (value <= hi):
        stdio.write(str(value) + ' ')
stdio.writeln()

#-----------------------------------------------------------------------

# python rangefilter.py 100 400
# 358 1330 55 165 689 1014 3066 387 575 843 203 48 292 877 65 998
# 358 165 387 203 292

Пример #49
0
def _regressionTest():
    """
    Perform regression testing.
    """

    clear()

    setPenRadius(.5)
    setPenColor(ORANGE)
    point(0.5, 0.5)
    show(0.0)

    setPenRadius(.25)
    setPenColor(BLUE)
    point(0.5, 0.5)
    show(0.0)

    setPenRadius(.02)
    setPenColor(RED)
    point(0.25, 0.25)
    show(0.0)

    setPenRadius(.01)
    setPenColor(GREEN)
    point(0.25, 0.25)
    show(0.0)

    setPenRadius(0)
    setPenColor(BLACK)
    point(0.25, 0.25)
    show(0.0)

    setPenRadius(.1)
    setPenColor(RED)
    point(0.75, 0.75)
    show(0.0)

    setPenRadius(0)
    setPenColor(CYAN)
    for i in range(0, 100):
        point(i / 512.0, .5)
        point(.5, i / 512.0)
    show(0.0)

    setPenRadius(0)
    setPenColor(MAGENTA)
    line(.1, .1, .3, .3)
    line(.1, .2, .3, .2)
    line(.2, .1, .2, .3)
    show(0.0)

    setPenRadius(.05)
    setPenColor(MAGENTA)
    line(.7, .5, .8, .9)
    show(0.0)

    setPenRadius(.01)
    setPenColor(YELLOW)
    circle(.75, .25, .2)
    show(0.0)

    setPenRadius(.01)
    setPenColor(YELLOW)
    filledCircle(.75, .25, .1)
    show(0.0)

    setPenRadius(.01)
    setPenColor(PINK)
    rectangle(.25, .75, .1, .2)
    show(0.0)

    setPenRadius(.01)
    setPenColor(PINK)
    filledRectangle(.25, .75, .05, .1)
    show(0.0)

    setPenRadius(.01)
    setPenColor(DARK_RED)
    square(.5, .5, .1)
    show(0.0)

    setPenRadius(.01)
    setPenColor(DARK_RED)
    filledSquare(.5, .5, .05)
    show(0.0)

    setPenRadius(.01)
    setPenColor(DARK_BLUE)
    polygon([.4, .5, .6], [.7, .8, .7])
    show(0.0)

    setPenRadius(.01)
    setPenColor(DARK_GREEN)
    setFontSize(24)
    text(.2, .4, 'hello, world')
    show(0.0)

    #import picture as p
    #pic = p.Picture('saveIcon.png')
    #picture(pic, .5, .85)
    #show(0.0)
    
    # Test handling of mouse and keyboard events.
    setPenColor(BLACK)
    import stdio
    stdio.writeln('Left click with the mouse or type a key')
    while True:
        if mousePressed():
            filledCircle(mouseX(), mouseY(), .02)
        if hasNextKeyTyped():
            stdio.write(nextKeyTyped())
        show(0.0)
        
    # Never get here.
    show()
Пример #50
0
# Import necessary modules.
import stdio
import stdarray

# Read x, y, and opt from standard input.
x = stdio.readString()
y = stdio.readString()
opt = stdarray.readInt2D()

# Compute M and N.
M = len(x)
N = len(y)

# Write edit distance between x and y.
stdio.write('Edit distance = ')
stdio.write(opt[0][0])
stdio.writeln()

# Recover and write an optimal alignment.
i = 0
j = 0

while i != M and j != N:
    if opt[i][j] == opt[i + 1][j] + 2:
        stdio.writef(x[i] + ' ' + '-' + ' ' + '2' + "\n")
        i += 1

    elif opt[i][j] == opt[i][j + 1] + 2:
        stdio.writef('-' + ' ' + y[j] + ' ' + '2' + "\n")
        j += 1
Пример #51
0
import stdio
import sys

# take three ints as input
x = (int(sys.argv[1]))
y = (int(sys.argv[2]))
z = (int(sys.argv[3]))

# find smallest, middle, and largest values
m = min(
    x,
    y,
    z,
)
M = max(
    x,
    y,
    z,
)
mid = (x + y + z) - (m + M)

# write numbers in ascending order
stdio.write(m)
stdio.write(' ')
stdio.write(mid)
stdio.write(' ')
stdio.writeln(M)
Пример #52
0
import stdio

#write 'Hello World' to stdout

stdio.write('Hello World!')
stdio.writeln()
stdio.write('YOOO')