JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Gallery
Solution Debug 7.3. Dodgy Doughnuts
Share
Explore
Gallery
Solution Debug 7.3. Dodgy Doughnuts
Solution Debug 7.3. Dodgy Doughnuts
Solution
The Task
Python Starter Code
CodeClips
Solution
Solution
solution
# sets up array of strings
doughnuts
=
[
'Chocolate Sprinkles'
,
'Lotus Biscoff'
,
'Glazed Raspberry'
,
'Vegan Caramel Iced Ring'
,
'Cookies and Kreme'
,
'Chocolate Dreamcake'
,
'Strawberries and Kreme'
,
'Original Glazed'
,
'Nutty Chocolatta'
,
'Vegan Strawberry Iced Ring'
]
# print the menu
print
(
'\n\nDoughnuts Menu\n\n'
)
# display all the doughnut options in the array
for
i
in
range
(
0
,
len
(
doughnuts
)
,
1
)
:
print
(
str
(
i
+
1
)
+
' : '
+
doughnuts
[
i
]
)
# end loop
print
(
'\n\n'
)
# display blank line (2)
# allow the customer to pick 4 doughnuts
for
i
in
range
(
0
,
4
,
1
)
:
# get the number for the doughnut
choice
=
int
(
input
(
'Pick your next doughnut, enter the menu number: '
)
)
# display the doughnut from the user's chosen array element
print
(
'Great choice - '
+
doughnuts
[
choice
-
1
]
)
print
(
"\n"
)
# end loop
original
# sets up array of strings
doughnuts
=
[
'Chocolate Sprinkles'
,
'Lotus Biscoff'
,
'Glazed Raspberry'
,
'Vegan Caramel Iced Ring'
,
'Cookies and Kreme'
,
'Chocolate Dreamcake'
,
'Strawberries and Kreme'
,
'Original Glazed'
,
'Nutty Chocolatta'
,
'Vegan Strawberry Iced Ring'
]
# print the menu
print
(
'\n\nDoughnuts Menu\n\n'
)
# display all the doughnut options in the array
for
i
in
range
(
0
,
4
,
1
)
:
print
(
str
(
i
+
1
)
+
' : '
+
doughnuts
[
1
]
)
# end loop
print
(
'\n\n'
)
# display blank line (2)
# allow the customer to pick 4 doughnuts
for
i
in
range
(
0
,
len
(
doughnuts
)
,
1
)
:
# get the number for the doughnut
choice
=
int
(
input
(
'Pick your next doughnut, enter the menu number: '
)
)
# display the doughnut from the user's chosen array element
print
(
'Great choice - '
+
doughnuts
[
i
]
)
print
(
"\n"
)
# end loop
Gallery
Share
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.