fork download
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import ex25
  5.  
  6. def break_words(stuff):
  7. """This function will break up words for us."""
  8. words = stuff.split(' ')
  9. return words
  10.  
  11. def sort_words(words):
  12. """Sorts the words."""
  13. return sorted(words)
  14.  
  15. def print_first_word(words):
  16. """Prints the first word after popping it off."""
  17. word = words.pop(0)
  18. print word
  19.  
  20. def print_last_word(words):
  21. """Prints the last word after popping it off."""
  22. word = words.pop(-1)
  23. print word
  24.  
  25. def sort_sentence(sentence):
  26. """Takes in a full sentence and returns the sorted words."""
  27. words = break_words(sentence)
  28. return sort_words(words)
  29.  
  30. def print_first_and_last(sentence):
  31. """Prints the first and last words of the sentence."""
  32. words = break_words(sentence)
  33. print_first_word(words)
  34. print_last_word(words)
  35.  
  36. def print_first_and_last_sorted(sentence):
  37. """Sorts the words then prints the first and last one."""
  38. words = sort_sentence(sentence)
  39. print_first_word(words)
  40. print_last_word(words)
  41.  
  42.  
  43. print "Let's practice everything."
  44. print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
  45.  
  46. poem = """
  47. \tThe lovely world
  48. with logic so firmly planted
  49. cannot discern \n the needs of love
  50. nor comprehend passion from intuition
  51. and requires an explantion
  52. \n\t\twhere there is none.
  53. """
  54.  
  55.  
  56. print "--------------"
  57. print poem
  58. print "--------------"
  59.  
  60. five = 10 - 2 + 3 - 6
  61. print "This should be five: %s" % five
  62.  
  63. def secret_formula(started):
  64. jelly_beans = started * 500
  65. jars = jelly_beans / 1000
  66. crates = jars / 100
  67. return jelly_beans, jars, crates
  68.  
  69.  
  70. start_point = 5000
  71. beans, jars, crates = secret_formula(start_point)
  72.  
  73. print "With a starting point of: %d" % start_point
  74. print "We'd have %d jeans, %d jars, and %d crates." % (beans, jars, crates)
  75.  
  76. start_point = start_point / 10
  77.  
  78. print "We can also do that this way:"
  79. print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_point)
  80.  
  81.  
  82. sentence = "All god things come to those who weight."
  83.  
  84. words = ex25.break_words(sentence)
  85. sorted_words = ex25.sort_words(words)
  86.  
  87. print_first_word(words)
  88. print_last_word(words)
  89. print_first_word(sorted_words)
  90. print_last_word(sorted_words)
  91. sorted_words = ex25.sort_sentence(sentence)
  92. print sorted_words
  93.  
  94. print_first_and_last(sentence)
  95.  
  96. print_first_and_last_sorted(sentence)
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: \35
#!/usr/bin/env python
^
Main.java:1: error: class, interface, or enum expected
#!/usr/bin/env python
  ^
Main.java:2: error: illegal character: \35
# -*- coding: utf-8 -*-
^
Main.java:4: error: '.' expected
import ex25
           ^
Main.java:6: error: ';' expected
def break_words(stuff):
   ^
Main.java:44: error: unclosed character literal
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
      ^
Main.java:44: error: illegal character: \92
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
          ^
Main.java:44: error: unclosed character literal
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
           ^
Main.java:44: error: illegal character: \92
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                           ^
Main.java:44: error: unclosed character literal
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                            ^
Main.java:44: error: illegal character: \92
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                                               ^
Main.java:44: error: illegal character: \92
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                                                ^
Main.java:44: error: illegal character: \92
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                                                          ^
Main.java:44: error: illegal character: \92
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                                                                          ^
Main.java:44: error: illegal line end in character literal
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
                                                                                  ^
Main.java:46: error: unclosed string literal
poem = """
         ^
Main.java:47: error: illegal character: \92
\tThe lovely world
^
Main.java:49: error: illegal character: \92
cannot discern \n the needs of love
               ^
Main.java:52: error: illegal character: \92
\n\t\twhere there is none.
^
Main.java:52: error: illegal character: \92
\n\t\twhere there is none.
  ^
Main.java:52: error: illegal character: \92
\n\t\twhere there is none.
    ^
Main.java:53: error: unclosed string literal
"""
  ^
22 errors
stdout
Standard output is empty