JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Gallery
Solution Debug 5.3. Baggage Check
Share
Explore
Gallery
Solution Debug 5.3. Baggage Check
Solution Debug 5.3. Baggage Check
Solution
The Task
Python Starter Code
Code Clips
Solution
Solution
solution
# set baggage limit to 40 (kgs)
baggageLimit
=
40
# print out a blank line
print
(
'\n'
)
# ask the user to enter weight of first bag
baggage1
=
int
(
input
(
'Please enter the weight of first bag (kg): '
)
)
# print out a blank line
print
(
'\n'
)
# ask the user to enter weight of second bag
baggage2
=
int
(
input
(
'Please enter the weight of second bag (kg): '
)
)
# print out a blank line
print
(
'\n\n'
)
# work out the total
totalBaggage
=
baggage1
+
baggage2
;
# checks the user guess
# if it is the same as the computer number, display well done
# anything else display sorry message.
if
totalBaggage
<
baggageLimit
:
print
(
'That is OK '
+
str
(
totalBaggage
)
+
' is under '
+
str
(
baggageLimit
)
+
' Kgs. Thanks! '
)
else
:
print
(
'Sorry '
+
str
(
totalBaggage
)
+
' is over '
+
str
(
baggageLimit
)
+
' Kgs. You can pay extra though.'
)
# print out a blank line
print
(
'\n'
)
original
# print out a blank line
print
(
'\n'
)
# ask the user to enter weight of first bag
baggage1
=
int
(
input
(
'Please enter the weight of first bag (kg): '
)
)
# print out a blank line
print
(
'\n'
)
# ask the user to enter weight of second bag
baggage2
=
int
(
input
(
'Please enter the weight of second bag (kg): '
)
)
# work out the total
totalBaggage
=
baggage1
+
baggage2
;
# checks the user guess
# if it is the same as the computer number, display well done
# anything else display sorry message.
if
totalBaggage
<
baggageLimit
print
(
'That is OK '
+
str
(
totalBaggage
)
+
' is under '
+
str
(
baggageLimit
)
+
' Kgs. Thanks! '
)
else
print
(
'Sorry '
+
str
(
totalBaggage
)
+
' is over '
+
str
(
baggageLimit
)
+
' Kgs. You can pay extra though.'
)
# print out a blank line
print
(
'\n'
)
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.