[Tutor] Beginning String Problems

Alan Thwaits basicbare at gmail.com
Thu Jan 2 06:19:54 EST 2020


I copied, pasted, and ran your code, and it worked well. I'm running
Anaconda3 and Spyder on a Windows 10 64-bit machine.

I'm very much a beginning Python user, so don't know enough to suggest why
it's not working for you. Just thought I'd let you know that your code
seems alright.

Cheers!

Alan

On Wed, Jan 1, 2020 at 7:15 PM William Dickey <wpdickey at usc.edu> wrote:

> I am learning Python via an online video "Beginning Python" by William
> Fiset. I am at the end of chapter 2 and I am supposed to be inputting a
> string that has an output of a persons full name in  this order *First M.
> Last*, but when I copied what he was doing it is not working. Here is what
> I input:
>
> first_name = str(input("Please enter your first name: "))
> middle_name = str(input("Please enter your middle name: "))
> last_name = str(input("Please enter your last name: "))
>
> first_name = first_name.capitalize()
> middle_name = middle_name.capitalize()
> last_name = last_name.capitalize()
>
> name_format = "{first} {middle:.1s} {last}"
> print(name_format.format(first=first_name, middle=middle_name,
> last=last_name))
>
> and here is what I get when I open it in the command line
>
> I enter the file location and I get:
> Please enter your first name:
>
> I enter william and I get this error:
>
> Traceback (most recent call):
>     File "C:\xxx\xxx\xxx\xxx", line 3, in <module>
>        first_name = str(input("Please enter your first name: "))
>     File "<string>", line 1, in <module>
> NameError: name 'william' is not defined
>
> I am using Windows 10 64 bit, Atom text editor, Python 3.4.
>
> Thank you
> William
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list