Challenge: Device Boots Count
Compito
Swipe to start coding
Imagine that you work in a company that produces devices. You have been tasked with developing a function that will count the number of boots on this device: with each boot, the device must increase the number of boots by 1.
- Define the
boots
variable in the global scope. - Make changeable the
boots
global variable inside theboot()
function local scope. - Increase the
boots
variable by 1 inside theboot()
function. - If the device is booting for the first time, display a message:
"The device boot for the first time"
. - If the device is booting 2+ times, display a message:
"The device boot N times"
, where N is aboots
variable.
Soluzione
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
boots = 0
def boot():
global boots
boots += 1
if boots == 1:
print("The device boot for the first time")
else:
print("The device boot", boots, "times")
boot()
boot()
boot()
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 1. Capitolo 5
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
___ = 0
def boot():
___ boots
boots += 1
if boots == 1:
print("___")
else:
print("The device boot", ___, "times")
boot()
boot()
boot()
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione