Exercise 18 stuck on debugging

My terminal tells me I got a problem on line 4 and have marked after the last ".
I tried to delete the whole first function, but still got same error on line 4.
Tried to manually indent 4 spaces - no difference
Tried single ’ instead of double " - still the same

Can anyone point me in the right direction?

#this one is like your scripts with argv
def print_two(*args):
    arg1, arg2 = args
    print(f"arg1: {arg1}, arg2: {arg2}")

# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
    print(f"arg1: {arg1}, arg2: {arg2}")

#this just takes one argument
def print_one(arg1):
    print(f"arg1: {arg1}")

#This one takes no arguments
def print_none():
    print("I got nothin'.")


print_two("Zed", "Shaw")
print_two_again("Zed", "Shaw")
print_one("First!")
print_none()

Hi again @ktrager - there is nothing wrong with the code you posted up. I strongly suspect you are running this in terminal but against Python 2 (default on many systems) and not Python 3. This would then make python complain about the f-string used.

What exactly is the problem in the terminal? Does it say:

SyntaxError: invalid syntax

For future use, it is good practice to post the terminal error too, as often this gets to the detail more succinctly that a user description can.

1 Like

Embarrassing, now it works.
I like to think I was running python 3 all the time yesterday, as I’m not even sure how to run python 2.

In the future - I’ll remember full terminal output aswell.

Assuming you’re on a Mac/Nix using Terminal, if you type:

python

to get the interpreter up and running, it will default to python 2 (2.7 usually) as that ships with the system.

Easily overcome by typing:

python3

or even more specifically if you have a version installed and want to use that one:

python3.6

Later in the book you’ll learn about setting up a virtual environment (VirtualEnv or venv) which makes the default python even easier. However, you then ‘forget’ to activate the environment and still get this issue, we all do!

I guess odds are I only used ‘python’…

1 Like

You can find out what python you’re running with:

python --version

1 Like