[英]how to store a random answer to use later in python
I am new to coding and thought id give python a try.我是编码新手,认为 id 可以尝试一下 python。 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?
假设有人输入“bob”或“Tingle”,该词将如何存储到变量中? 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
. raw_input
将返回您输入的内容,因此original
变量将存储您输入的字符串,其类型为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(按回车键)
bob鲍勃
b乙
thanks for the help谢谢您的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.