[Tutor] Beginning String Problems

William Dickey wpdickey at usc.edu
Wed Jan 1 18:22:22 EST 2020


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


More information about the Tutor mailing list