From b2f7535ee0f6d68daf61efc2d95fb4496f6aebf8 Mon Sep 17 00:00:00 2001 From: nnnkkk9 <52539849+nnnkkk9@users.noreply.github.com> Date: Mon, 18 May 2020 12:24:55 -0400 Subject: [PATCH] int function for the "how_many" variable in line 24 I have tried the original code on Python 3.8.2 but it kept showing errors " 'str' object cannot be interpreted as an integer". While reading the traceback, I noticed in line 24, the variable "how_many" was acted as a string variable, not an integer one (I would love if someone explained to me why even though it was defined as an integer the function's argument). The only thing I did was to add int() to the "how_many" variable to convert it into an integer one. When I tested it back on my device, it worked like charm --- intro-python/part2/fortune_cookie.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intro-python/part2/fortune_cookie.py b/intro-python/part2/fortune_cookie.py index d7ea94908..d8559ba7d 100755 --- a/intro-python/part2/fortune_cookie.py +++ b/intro-python/part2/fortune_cookie.py @@ -21,7 +21,7 @@ def generate_fortune() -> str: def generate_lucky_numbers(how_many: int) -> list: """Returns a list of (random) 'lucky' numbers.""" lucky_numbers = [] - for _ in range(how_many): + for _ in range(int(how_many)): lucky_numbers.append(random.randint(0, 99)) return lucky_numbers