Re: Need help with a script

I will provide the fixed script and will comment the things I've changed and or added

def countdown(n):
    #Don't get the user input in the function, as doing so will basically cause them to reenter a number every time a program runs
    if n <= 0:
        print('blast off!')
    else:
        print(n)
        countdown(n-1)

#now, here's the tricky part. input() takes the user input in as a string. This means that we will have to convert whatever you've entered into an integer before passing it along to the countdown function
#I'll write two versions: Here is the first one, which is a bit easier to understand
n = input('Put a number in.')
#Now, convert the thing to integer by using int()
n = int(n)
countdown(n)
#Here's a second version, basically the same thing but condensed
countdown(int(input('Put a number in.')))

End code
I should mention that this will crash should you enter an invalid string to be converted to an integer. There is a way to stop that as well, but I digress.
Hope this was helpful.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : microsoftsam203 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : microsoftsam203 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : microsoftsam203 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : microsoftsam203 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Munawar via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : microsoftsam203 via Audiogames-reflector

Reply via email to