Skip to content
← Back to Community
How to get an input accept words and letters instead of just numbers
Profile icon
STCollier

In Python 2.7, it can be extremely frustrating (at least for me) to have something such as

noun = input("Insert a noun: ")

and when you run the program, and error message shows up. This is because the input will only accept numbers. In order to have the input accept anything, so in this case letters (and even symbols), you must change the "input" to "raw_input" and all your problems will be fixed. So the fixed code from the following example will look like this:

noun = raw_input("Insert a noun: ")

Hope this helps anyone.

Voters
Profile icon
STCollier
Comments
hotnewtop
Profile icon
SEO-JinPARK

I did this:

#Mad Libs
print("Welcome to MadLibs Replit! Please feel free to laugh your head off. Thank you.")
print(" ")
print(" ")
print("***************************************************************")
print(" ")
print(" ")
print("Fill in the blanks. Be as crazy and silly as you can. Enjoy!")
print(" ")
print("Chocolate")
print(" ")
blank1 = str(input("Person's name: "))
blank2 = str(input("Color: "))
blank3 = str(input("Noun: "))
blank4 = str(input("Somthing you could tasete: "))
blank5 = str(input("Adjective: "))
blank6 = str(input("Noun (PLURAL) : "))
blank7 = str(input("Holiday: "))
blank8 = str(input("Noun: "))
blank9 = str(input("Number: "))
blank10 = str(input("Noun:"))
generate = str(input("Type in 'go' to generate MadLib\n"))
if generate == "go":
print(" ")
print("Dear",blank1,(","))
print(" ")
print("Thanks for placing your chocolate order with the",blank2, blank3, ("Chocolate Company. "))
print("Unfortunately, your",blank4, ("flavored chocolates are unavailable right now because"))
print(blank5,blank6,("accidentally fell in our chocolate vat. We’re sorry for any inconvenience"))
print("this caused. Since you were ordering these for a party to celebrate",blank7,(", we would"))
print("like to offer you",blank8,("shaped truffles at a discount of",blank9,("dollars instead.")))
print(" ")
print("Sincerely,")
print(" ")
print("John",blank10,("Spooner"))
print(" ")

Profile icon
hg0428
Profile icon
hg0428

That was fixed in python 3

Profile icon
STCollier

@hg0428 I literally just started programming when I wrote that comment, so I was kinda dumb lol

Profile icon
hg0428

I never even learned python 2.
I made a lot of dumb posts and videos when I started.
@STCollier