How do i use prompt() function in python3.11.4

Hi, self learning python. I’m wondering if i need to call a toolkit or module? my book says to type.

fname = input("What is your first name? ")
lname = prompt("What is ypur last name? ")

print("First name first: ",fname, lname);
print("Last name first: ", lname, ", ", fname);

and i when i run the program, it says

NameError: name 'prompt'  is not defined

Use input like you did with fname

1 Like

or first set prompt = input. but the duplication is not usually a good idea.

1 Like

We would need more context from the book itself, in order to understand whether the book is wrong, whether you were asked to do something else first in order to make it work, etc. etc.

That said, this example doesn’t look very promising. The semicolons are completely unnecessary, and a sign of someone who is not familiar and comfortable with Python. If you’re self learning, that’s to be expected. But if that’s the author of the book you’re reading, well, that’s a problem :slight_smile:

4 Likes

thanks for all the replies and suggestions. im reading sams teach yourself:
Beginning Programming. I reread that section and the authors don’t mention if need to do something prior and the author adds the semicolon in the “Try it yourself” lessons.
ed

Yeah, that series of books doesn’t have a great reputation IIRC. The premise of teaching yourself a programming language in such a short time span is completely flawed anyway :slight_smile:

2 Likes

I see that the title of the book is Teach Yourself in 24 Hours, with 320 pages. I don’t think that I agree with that.

I have been at it for a few months now, and still learning using Learning Python, 5th Edition, with 1594 pages. Try this one out. It is much more comprehensive and thorough. It covers the fundamental topics in depth giving you a strong foundation - in my humble opinion.

1 Like

thanks! ill grab a copy. Karl mentioned these books don’t have a good reputation.

Yeah, try reading it from beginning to end in a linear manner. Take your time. Learn at your own pace. Expect to invest many months reading this book as it is comprehensive and thorough.

Good luck!

Btw, it is available in e-book version as well.

1 Like

FWIW such a function exists in JavaScript. Perhaps, the book wanted you to open a web browser (like Mozilla Firefox or Google Chrome), hit F12 opening DevTools and type it into the JS console, not into a Python REPL. But that’s definitely not something built into Python.

1 Like

Note that this line outputs unnecessary spaces between the tokens, resulting in a weirdly formatted output.

I also just Googled an ebook version of this book and found the original section containing this code example. The text explaining the concepts is so riddled with inaccuracies and errors I would urge you to throw away/burn to ashes this book as soon as you can.

2 Likes