Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3d072c95
Commit
3d072c95
authored
Oct 10, 2009
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show use of range() step argument nicely.
parent
0b798a9d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
Demo/scripts/beer.py
Demo/scripts/beer.py
+11
-5
No files found.
Demo/scripts/beer.py
View file @
3d072c95
#! /usr/bin/env python
#! /usr/bin/env python
# By GvR, demystified after a version by Fredrik Lundh.
# By GvR, demystified after a version by Fredrik Lundh.
import
sys
import
sys
n
=
100
n
=
100
if
sys
.
argv
[
1
:]:
n
=
int
(
sys
.
argv
[
1
])
if
sys
.
argv
[
1
:]:
n
=
int
(
sys
.
argv
[
1
])
def
bottle
(
n
):
def
bottle
(
n
):
if
n
==
0
:
return
"no more bottles of beer"
if
n
==
0
:
return
"no more bottles of beer"
if
n
==
1
:
return
"one bottle of beer"
if
n
==
1
:
return
"one bottle of beer"
return
str
(
n
)
+
" bottles of beer"
return
str
(
n
)
+
" bottles of beer"
for
i
in
range
(
n
):
print
bottle
(
n
-
i
),
"on the wall,"
for
i
in
range
(
n
,
0
,
-
1
):
print
bottle
(
n
-
i
)
+
"."
print
bottle
(
i
),
"on the wall,"
print
bottle
(
i
)
+
"."
print
"Take one down, pass it around,"
print
"Take one down, pass it around,"
print
bottle
(
n
-
i
-
1
),
"on the wall."
print
bottle
(
i
-
1
),
"on the wall."
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment