0

I am new to python, I am learning it through reading a book(Learn Python 3 the hard way). There is an exercise(exercise14)in the book can’t be run using iOS Pythonista 3.

The script is below:

from sys import argv

script, user_name = argv
prompt = '> '

print(f"Hi {user_name}, I'm the {script} script.")

print("I'd like to ask you a few questions.")

print(f"Do you like me {user_name}?")

likes = input(prompt)

print(f"Where do you live {user_name}?")

lives = input(prompt)

print("What kind of computer do you have?")

computer = input(prompt)

print(f"""
    Alright, so you said {likes} about liking me.
    You live in {lives}.  Not sure where that is.
     And you have a {computer} computer.  Nice.
     """)

But then I got an error:

  File "/private/var/mobile/Containers/Shared/AppGroup/726BC931-58AE-44A6-9BE5-067EF23667A4/Pythonista3/Documents/Untitled.py", line 2, in <module>
    script, user_name = argv
ValueError: not enough values to unpack (expected 2, got 1)

Please help me to solve this problem , I am very new.

Thank you guys!

  • From the error it looks like there's a `2` at the end of line 1 in your file. Have you checked whether that's the case, removed it and saved the file again? – D Malan Sep 23 '22 at 13:48
  • Hi D, thanks, I have removed the 2 from the end of line 1, but ,got the same error. – Zhāng JìngYè Sep 23 '22 at 14:33
  • The error you pasted now is a different one and belongs in a separate Stackoverflow question. – D Malan Sep 25 '22 at 09:09

1 Answers1

1

If you long-press the run ("play") button on Pythonista, you can add the command-line argument that your script is expecting (user name, the script name it gets by default).

Mikael
  • 136
  • 1
  • 5