简体   繁体   中英

how to store a random answer to use later in python

I am new to coding and thought id give python a try. This is what I am seeing:

 original = raw_input('Enter a word:') # how to store answer to this

 if len(original) > 0 and original.isalpha():

    print original.lower() 

I want to know how to store any random word in response to "Enter a word". Say if someone typed "bob" or "Tingle" how would that word be stored to a variable? ie variable = "answer"

raw_input will return what you typed,so the original variable will store the string you typed and its type is string .

For example:

>>> original = raw_input('Enter a word:')
Enter a word:value
>>> original
'value'
>>> 

figured it out... I think!

original = raw_input('Enter a word:')
if len(original) > 0 and original.isalpha():
    print original.lower()
first = original[0].lower()
print first
word = original.lower()

on screen would return:

Enter a word: Bob (hit enter)

bob

b

thanks for the help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM