Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
LearnPythonHardWay/ex26-1.py at master · 6188506/LearnPythonHardWay · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
6188506
LearnPythonHardWay
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
LearnPythonHardWay
/
ex26-1.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
90 lines (67 loc) · 2.25 KB
master
Breadcrumbs
LearnPythonHardWay
/
ex26-1.py
Copy path
Top
File metadata and controls
Code
Blame
90 lines (67 loc) · 2.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def
break_words
(
stuff
):
"""This function will break up words for us."""
words
=
stuff
.
split
(
' '
)
return
words
def
sort_words
(
words
):
"""Sorts the words."""
return
sorted
(
words
)
def
print_first_word
(
words
):
"""Prints the first word after popping it off."""
word
=
words
.
pop
(
0
)
print
word
def
print_last_word
(
words
):
"""Prints the last word after popping it off."""
word
=
words
.
pop
(
-
1
)
print
word
def
sort_sentence
(
sentence
):
"""Takes in a full sentence and returns the sorted words."""
words
=
break_words
(
sentence
)
return
sort_words
(
words
)
def
print_first_and_last
(
sentence
):
"""Prints the first and last words of the sentence."""
words
=
break_words
(
sentence
)
print_first_word
(
words
)
print_last_word
(
words
)
def
print_first_and_last_sorted
(
sentence
):
"""Sorts the words then prints the first and last one."""
words
=
sort_sentence
(
sentence
)
print_first_word
(
words
)
print_last_word
(
words
)
print
"Let's practice everything."
print
'You
\'
d need to know
\'
bout escapes with
\\
that do
\n
newlines and
\t
tabs.'
poem
=
"""
\t
The 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
\t
where there is none.
"""
print
"--------------"
print
poem
print
"--------------"
five
=
10
-
2
+
3
-
5
print
"This should be five: %d"
%
five
#modify format string
def
secret_formula
(
started
):
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 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
\t
things come to those who weight."
words
=
break_words
(
sentence
)
sorted_words
=
sort_words
(
words
)
print_first_word
(
words
)
print_last_word
(
words
)
print_first_word
(
sorted_words
)
print_last_word
(
sorted_words
)
sorted_words
=
sort_sentence
(
sentence
)
print
sorted_words
print_first_and_last
(
sentence
)
print_first_and_last_sorted
(
sentence
)
You can’t perform that action at this time.