Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Programs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Akhil
Programs
Commits
f55b7abe
Commit
f55b7abe
authored
Nov 18, 2020
by
Akhil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
for loops and turtle example
parent
6f533453
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
Python/turtle.py
Python/turtle.py
+45
-0
No files found.
Python/turtle.py
0 → 100644
View file @
f55b7abe
'''
cellphone attributes : size , weight, dimensions,
cellphone methods : scroll ,
'''
'''
Write a program that uses a for loop to print
One of the months of the year is January
One of the months of the year is February
'''
months
=
[
'jan'
,
'feb'
,
'mar'
,
'apr'
,
'may'
,
'june'
,
'july'
,
'aug'
,
'sept'
,
'oct'
,
'nov'
,
'dec'
]
for
month
in
months
:
print
(
'One of the months of the year is '
,
month
)
for
i
in
range
(
1000
):
print
(
'print this 1000 times'
)
'''
Assume you have the assignment xs = [12, 10, 32, 3, 66, 17, 42, 99, 20]
(a) Write a loop that prints each of the numbers on a new line.
(b) Write a loop that prints each number and its square on a new line.
(c) Write a loop that adds all the numbers from the list into a variable called total. You
should set the total variable to have the value 0 before you start adding them up,
and print the value in total after the loop has completed.
(d) Print the product of all the numbers in the list. (product means all multiplied to-
gether)'''
xs
=
[
12
,
10
,
32
,
3
,
66
,
17
,
42
,
99
,
20
]
for
i
in
xs
:
print
(
i
)
for
i
in
xs
:
print
(
i
,
i
*
i
)
total
=
0
for
i
in
xs
:
total
+=
i
print
(
total
)
product
=
1
for
i
in
xs
:
product
*=
1
print
(
product
)
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