I am trying to make a script to check if an argument was entered. If an argument was entered it uses that number for the timer, if no argument was entered, then by default, the timer should equal 3.
This while loop will count down from the given number & print each value as it counts down. When it gets to the end it will output 'blast off!'
#!/usr/bin/env python3
import sys
timer = int(sys.argv[1])
while timer != 0:
if len(sys.argv[1]) == 0:
timer = 3
elif len(sys.argv[1]) == int(sys.argv[1]):
timer = int(sys.argv[1])
print (timer)
timer = timer - 1
print ('blast off!')
My homework checking script gives me an error of IndexError: list index out of range - related to the first timer = int(sys.argv[1])
I am not sure how exactly I am supposed to "convert an empty string into an integer"
Thank you