05-08-2020 12:32 AM
I'm going through the Devnet learning track and I have an issue with the interpreter )> Apparently they would not recognize the '->'
When I run it - it hangs there with a syntax error.
I understand a syntax error, but it won't go away.
Any thoughts how to solve?
Tested this with windows cmd python, in git bash ...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Script flow and debugging. Print your own fortune cookie!"""
import random
FORTUNES = [
" There is always good weather some day ",
" One day you will have a happy day ",
" Your kids would listen if you ask them something",
]
def generate_fortune() -> str:
return random.choice(FORTUNES)
def generate_lucky_numbers(how_many: int) -> list:
lucky_numbers = []
for _ in range(how_many:):
lucky_number..............................
Solved! Go to Solution.
05-08-2020 08:04 AM
I suggest .. trying to copy or download the file again -
https://github.com/CiscoDevNet/intro-python-code/blob/solutions/intro-python/part2/fortune_cookie.py
05-08-2020 01:56 AM
Hi
Can you share the error you are getting?
Check the version of Python you are using.
The code works in Python3.
05-08-2020 05:28 AM
05-08-2020 05:42 AM
05-08-2020 06:39 AM - edited 05-08-2020 06:41 AM
Check your syntax you might have added or deleted something .. on line 13 .. do still have the closing bracket " ] " for the list?
Does your line 9 - 18 look like this ..
FORTUNES = [ "There is a good chance your code will work, eventually.", "The weather will be hot, cold or just right today.", "I see Network DevOps in your future.", ]
def generate_fortune() -> str: """Use mystical forces (a random selection) to get a user's fortune.""" return random.choice(FORTUNES)
I can reproduce the same error if I remove the closing bracket
python3 fortune_cookie.py File "fortune_cookie.py", line 16 def generate_fortune() -> str: ^ SyntaxError: invalid syntax
05-08-2020 06:53 AM
05-08-2020 08:04 AM
I suggest .. trying to copy or download the file again -
https://github.com/CiscoDevNet/intro-python-code/blob/solutions/intro-python/part2/fortune_cookie.py
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide