Esempio n. 1
0
def main():
    sentence = "All good things come to those who wait."
    words = ex25.break_words(sentence)
    print(words)
    sorted_words = ex25.sort_words(words)
    print(sorted_words)
    ex25.print_first_word(sorted_words)
    ex25.print_last_word(sorted_words)
    print(sorted_words)
    sorted_words = ex25.sort_sentence(sentence)
    print(sorted_words)
    ex25.print_first_and_last(sentence)
    ex25.print_first_and_last_sorted(sentence)
Esempio n. 2
0
File: ex26.py Progetto: arante/pyloc
def main():
    """Exercise 26: Congratulations, Take a Test!"""
    print "Let's practice everything."
    print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'

    poem = """
    \tThe lovely world
    with logic so firmly planted
    cannot discern \n the needs of love
    nor comprehend passion from intuition
    and requires an explantion
    \n\t\twhere there is none.
    """


    print "--------------"
    print poem
    print "--------------"

    five = 10 - 2 + 3 - 5
    print "This should be five: %s" % five

    start_point = 10000
    beans, jars, crates = secret_formula(start_point)

    print "With a starting point of: %d" % start_point
    print "We'd have %d jeans, %d jars, and %d crates." % (beans, jars, crates)

    start_point = start_point / 10

    print "We can also do that this way:"
    print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_point)


    sentence = "All god\tthings come to those who weight."

    words = ex25.break_words(sentence)
    sorted_words = ex25.sort_words(words)

    print_first_word(words)
    print_last_word(words)
    print_first_word(sorted_words)
    print_last_word(sorted_words)
    sorted_words = ex25.sort_sentence(sentence)
    print sorted_words

    print_first_and_last(sentence)

    print_first_and_last_sorted(sentence)
Esempio n. 3
0
    jelly_beans = started * 500
    jars = jelly_beans / 1000
    crates = jars / 100
    return jelly_beans, jars, crates


start_point = 10000
beans, jars, crates = secret_formula(start_point)

print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates)

start_point = start_point / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)


sentence = "All good things come to those who wait."

import ex25
words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)

print_first_word(words)
print_last_word(words)
print_first_word(sorted_words)
print_last_word(sorted_words)
print ex25.sort_sentence(sentence)
print_first_and_last(sentence)
print_first_and_last_sorted(sentence)
import ex25
sentence = "All good things come to those who wait."
words = ex25.break_words(sentence)
print words

sorted_words = ex25.sort_words(words)
print sorted_words

ex25.print_first_word(words)

ex25.print_last_word(words)

sorted_words = ex25.sort_sentence(sentence)

print sorted_words

ex25.print_first_and_last(sentence)

ex25.print_first_and_last_sorted(sentence)

help(ex25)
Esempio n. 5
0
    beans = started * 500
    jars = beans / 1000
    crates = jars / 100
    return beans, jars, crates


start_point = 10000
beans, jars, crates = secret_formula(start_point)

print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates)

start_point = start_point / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(
    start_point)

words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)

print_first_word(words)
print_last_word(words)
print_first_word(sorted_words)
print_last_word(sorted_words)
sort_words = ex25.sort_sentence(sentence)
print_sorted_words = ex25.sort_sentence(sentence)

print_first_and_last(sentence)

print_first_and_last_sorted(sentence)
Esempio n. 6
0
import ex25
sentence = 'All good thing come to those who wait.'
words = ex25.break_words(sentence)
print(words)
print(ex25.sort_words(words))
ex25.print_first_word(words)
ex25.print_last_word(words)
print(words)
print(ex25.sort_sentence(sentence))
ex25.print_first_and_last(sentence)
ex25.print_first_and_last_sorted(sentence)
Esempio n. 7
0
from hello import print_hello
import ex25

print_hello()

ex25.break_words("sting like a bee")
ex25.print_first_and_last("sting like a bee")
ex25.print_first_word("sting like a bee")
ex25.print_last_word("sting like a bee")
ex25.sort_sentence("sting like a bee")
ex25.sort_words("sting like a bee")
Esempio n. 8
0
def print_first_and_last_sorted(sentence):
    """Sorts the words then prints the first and last one."""
    words = ex25.sort_sentence(sentence)
    ex25.print_first_word(words)
    ex25.print_last_word(words)
Esempio n. 9
0
from ex25a import adder
import ex25

print(adder(3, 4))
line = "this is new line not the previous one"
words = ex25.break_words(line)
print(words)
print(ex25.sort_words(words))
ex25.print_first_word(words)
ex25.print_last_word(words)
print(ex25.sort_sentence(line))
ex25.print_first_and_last(line)
ex25.print_first_and_last_sorted(line)
Esempio n. 10
0
import ex25
sentence = "The quick brown fox jumps over the lazy dog."
words = ex25.break_words(sentence)
print ex25.break_words(sentence)
print "\n"
print ex25.sort_words(words)
print "\n"
print ex25.print_first_word(words)
print "\n"
print ex25.print_last_word(words)
print "\n"
print ex25.sort_sentence(sentence)
print "\n"
print ex25.print_first_and_last(sentence)
print "\n"
print ex25.print_first_and_last_sorted(sentence)

Esempio n. 11
0
print "----------"
print "first sorted words"
print "ex25.print_first_word(sorted_words)"
print "first sorted words = ", ex25.print_first_word(sorted_words)

print "----------"
print "last sorted words"
print "ex25.print_last_word(sorted_words)"
print "last sorted words = ", ex25.print_last_word(sorted_words)

print "----------"
print "now sorted words"
print "sorted words = ", sorted_words

print "----------"
print "make new sorted words by sort sentence"
print "sorted_words = ex25.sort_sentence(sentence)"
ex25.sort_sentence(sentence)
print "sorted_words = ", sorted_words

print "----------"
print "first and last word of sentence"
print "ex25.print_first_and_last(sentence)"
ex25.print_first_and_last(sentence)

print "----------"
print "first and last word of sorted sentence"
print "ex25.print_first_and_last_sorted(sentence)"
ex25.print_first_and_last_sorted(sentence)
Esempio n. 12
0
print "----------"
print "first sorted words"
print "ex25.print_first_word(sorted_words)"
print "first sorted words = ", ex25.print_first_word(sorted_words)

print "----------"
print "last sorted words"
print "ex25.print_last_word(sorted_words)"
print "last sorted words = ", ex25.print_last_word(sorted_words)

print "----------"
print "now sorted words"
print "sorted words = ", sorted_words

print "----------"
print "make new sorted words by sort sentence"
print "sorted_words = ex25.sort_sentence(sentence)"
ex25.sort_sentence(sentence)
print "sorted_words = ", sorted_words

print "----------"
print "first and last word of sentence"
print "ex25.print_first_and_last(sentence)"
ex25.print_first_and_last(sentence)

print "----------"
print "first and last word of sorted sentence"
print "ex25.print_first_and_last_sorted(sentence)"
ex25.print_first_and_last_sorted(sentence)
Esempio n. 13
0
START_POINT = 10000
BEANS, JARS, CRATES = secret_formula(START_POINT)

print "With a starting point of: %d" % START_POINT
print "We'd have %d beans, %d jars, and %d crates." % (BEANS, JARS, CRATES)

START_POINT = START_POINT / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(
    START_POINT)


SENTENCE = "All good things come to those who wait."

import ex25

WORDS = ex25.break_words(SENTENCE)
SORTED_WORDS = ex25.sort_words(WORDS)

print_first_word(WORDS)
print_last_word(WORDS)
print_first_word(SORTED_WORDS)
print_last_word(SORTED_WORDS)
SORTED_WORDS = ex25.sort_sentence(SENTENCE)
print SORTED_WORDS

print_first_and_last(SENTENCE)

print_first_and_last_sorted(SENTENCE)
Esempio n. 14
0
start_point = start_point / 10

print("We can also do that this way:")
print("We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_point))


sentence = "All god\tthings come to those who weight."

words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)

print_first_word(words) # All
print_last_word(words)  # weight
print_first_word(sorted_words) # All
print_last_word(sorted_words)  # who, 按照切片后排序的顺序来的
sorted_words = ex25.sort_sentence(sentence) # 对 sentence 变量进行切片,返回切边的排序
print(sorted_words)

print_first_and_last(sentence) # All

print_first_and_last_sorted(sentence) # weight


"""
1. 16行 poop --> pop
2. 21行 最后加括号 )
3. 14行 函数最后加冒号 :
4. 70行 == --> = ; start-point --> start_point
5. 73行 jeans --> beans
6. 78行 start_pont --> start_point; 最后加上两个括号 ))
7. 88行 去掉第一个.