Python Forum
If the argument is not int then make it int!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If the argument is not int then make it int!
#3
I think you are trying to write:
if type(n) is not int:
    n = int(n)
But since it is valid to pass an integer to int() why not just do this?
def countdown(n):
    n = int(n)
    while n > 0:
        print(n)
        n = n - 1
    print('Blastoff!')
Or this
def countdown(n):
    for i in range(int(n), 0, -1):
        print(i)
    print('Blastoff!')
pooyan89 likes this post
Reply


Messages In This Thread
RE: If the argument is not int then make it int! - by deanhystad - Dec-11-2020, 02:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  creating functions - make optional argument a reversal anstuteville 2 2,684 Aug-31-2018, 02:36 PM
Last Post: anstuteville

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020