newb? [英] newb ?
问题描述
嘿伙计们,
我回来了。试图扩展书中给出的一个程序我是学习的。
不,我不是高中或大学生。这样做我自己。并且
有很多麻烦
我正在尝试为一个单词jumble程序添加一个提示部分。
我得到一个追溯错误,即混乱中的单词没有被定义。
任何人都可以帮忙吗?
谢谢,
随机导入
#创建一系列单词可供选择
WORDS =(" python",easy)
#从序列中随机选择一个单词
word = random.choice(WORDS)
#创建一个变量,以便稍后用来查看猜测是否正确
correct = word
#如果需要,创建用于提示的变量
#创建一个混乱版本的单词
jumble =""
而单词:
position = random.randrange(len(word))
jumble + = word [位置]
字=字[:位置] +字[(位置+ 1):]
#开始游戏
打印\
"""
欢迎来到Word Jumble!
解读这些字母以赚取一个字。
(在提示符下按回车键退出。)
"""
print" the jumble is:",jumble
print"如果你需要一个提示类型''提示''和点击输入。"
guess = raw_input(" \ n你的猜测:")
guess = guess.lower()
while(guess!= correct)和(guess!="")和(guess!= hint):##不确定
关于这个##
打印对不起,那不是。
guess = raw_input("你的猜测:")
guess = guess.lower()
###我不知道如何设置这个部分是正确的,这样当他们要求
提示它会给它时他们###
而word == easy:
如果猜= =提示:
打印不是很难但是
guess = raw_input("你的猜测:")
guess = guess.lo wer()
而word == python:
如果猜= =提示:
print" snake"
guess = raw_input("你的猜测:")
guess = guess.lower()
如果猜测==正确:
print"就是这样!你猜对了!\ n"
打印感谢您的演奏。
raw_input(" \ n \ n按回车键退出。
Hey guys,
I am back. Trying to expand on a program that was given in the book I am
studying.
No I am not a high school or college student. Doing this on my own. and
having way to much trouble
I am trying to add a hint section to a word jumble program.
I get a traceback error that the word in the jumble is not defined.
Can anyone help?
thanks,
import random
# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed
# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
# start the game
print \
"""
Welcome to Word Jumble!
Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type ''hint'' and Hit enter."
guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##
print "Sorry, that''s not it."
guess = raw_input("Your guess: ")
guess = guess.lower()
###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###
while word == easy:
if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()
while word == python:
if guess == hint:
print "snake"
guess = raw_input("Your guess: ")
guess = guess.lower()
if guess == correct:
print "That''s it! You guessed it!\n"
print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
推荐答案
Chad Everett写道:
Chad Everett wrote:
嘿伙计们,
我回来了。试图扩展我正在学习的书中给出的一个项目。
不,我不是高中或大学生。这样做我自己。并且有很多麻烦
我正在尝试为一个单词jumble程序添加一个提示部分。
我得到一个跟踪错误,该单词在jumble没有定义。
任何人都可以帮忙吗?
你有几个错误。
谢谢,
随机导入
#创建一个序列单词可供选择
WORDS =(" python",easy)
#从序列中随机选择一个单词
word = random.choice(WORDS)
#创建一个变量以便稍后使用以查看猜测是否正确
correct = word
#create变量用于提示如果需要
你没有在这里创建一个变量。像
hint =" hint"
这是你问题的核心。你将一个
变量名称与分配给它的值混淆。
#创建一个混乱版本的单词
jumble ="" ;
而单词:
position = random.randrange(len(word))
jumble + = word [position]
word = word [:position] + word [(位置+ 1):]
#开始游戏
打印\
"""
欢迎来到Word Jumble!
>解读字母以表达一个单词。
(在提示符下按回车键退出。)
"""
print" jumble is:,jumble
print"如果你需要一个提示类型''提示''并点击输入。
这里你明确告诉用户提示词是提示。
guess = raw_input(" \\\
Your guess:" )
guess = guess.lower()
while(guess!= correct)和(guess!="")和(guess!= hint):##不确定
关于这个##
它会失败,因为你没有定义提示变量。
注意你实际上不需要一个提示变量(因为
提示词永远不会改变),你可以说
....和(猜测!="提示")
而(猜测!=正确)需要与变量
进行比较,因为正确的确会改变。
print"抱歉,那不是它。
guess = raw_input("你的猜测:")
guess = guess.lower()
###我不知道如何设置这个部分是正确的,这样当他们要求提示时它会给他们###
而word == easy:
这里同样的问题,容易变量(你还没定义)。
你的意思是
而word ==easy:
如果猜= =提示:
打印不是很难,但是
guess = raw_input("你的猜测:")
guess = guess.lower()
而word == python:
同上。但是当你的单词列表变大时,这将变得乏味。
你应该将你的单词及其提示存储在字典中:
hints = { ''easy'':''不难但'',''python'':'''蛇''}
然后你需要一个可以打印出来的单个代码块提示
使用正确的单词查找词典中的提示。
如果猜= =提示:
打印提示[正确]
guess = raw_input("你的猜测:")
guess = guess.lower()
如果猜测==正确:
print"就是这样!你猜对了!\ n"
打印感谢您的播放。
raw_input(\ n \ n按回车键退出。 ;)
Hey guys,
I am back. Trying to expand on a program that was given in the book I am
studying.
No I am not a high school or college student. Doing this on my own. and
having way to much trouble
I am trying to add a hint section to a word jumble program.
I get a traceback error that the word in the jumble is not defined.
Can anyone help?
You have several errors.
thanks,
import random
# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed
You didn''t create a variable here. Something like
hint = "hint"
And this is the core of your problems. You are confusing a
variable name with the value assigned to it.
# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
# start the game
print \
"""
Welcome to Word Jumble!
Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type ''hint'' and Hit enter."
Here you have specifically told the user that the hint word is "hint".
guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##
It will fail because you did not define the hint variable.
Note you actually don''t need a hint variable (because the
hint word never changes), you could have said
.... and (guess != "hint")
whereas (guess != correct) needs to compare against a variable
because correct does change.
print "Sorry, that''s not it."
guess = raw_input("Your guess: ")
guess = guess.lower()
###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###
while word == easy:
Same problem here, easy is a variable (which you haven''t defined).
What you meant to say was
while word == "easy":
if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()
while word == python:
Ditto. But this is going to get tedious when your word list gets large.
You should have your words and their hints stored in a dictionary:
hints = {''easy'':''not hard but'',''python'':''snake''}
then you need just a single code block that can print the hint
by using the correct word to look up the hint in the dictionary.
if guess == hint:
print hints[correct]
guess = raw_input("Your guess: ")
guess = guess.lower()
if guess == correct:
print "That''s it! You guessed it!\n"
print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
Chad Everett写道:
Chad Everett wrote:
嘿伙计们,
我回来了。试图扩展我正在学习的书中给出的一个项目。
不,我不是高中或大学生。这样做我自己。并且有很多麻烦
我正在尝试为一个单词jumble程序添加一个提示部分。
我得到一个跟踪错误,该单词在jumble没有定义。
任何人都可以帮忙吗?
你有几个错误。
谢谢,
随机导入
#创建一个序列单词可供选择
WORDS =(" python",easy)
#从序列中随机选择一个单词
word = random.choice(WORDS)
#创建一个变量以便稍后使用以查看猜测是否正确
correct = word
#create变量用于提示如果需要
你没有在这里创建一个变量。像
hint =" hint"
这是你问题的核心。你将一个
变量名称与分配给它的值混淆。
#创建一个混乱版本的单词
jumble ="" ;
而单词:
position = random.randrange(len(word))
jumble + = word [position]
word = word [:position] + word [(位置+ 1):]
#开始游戏
打印\
"""
欢迎来到Word Jumble!
>解读字母以表达一个单词。
(在提示符下按回车键退出。)
"""
print" jumble is:,jumble
print"如果你需要一个提示类型''提示''并点击输入。
这里你明确告诉用户提示词是提示。
guess = raw_input(" \\\
Your guess:" )
guess = guess.lower()
while(guess!= correct)和(guess!="")和(guess!= hint):##不确定
关于这个##
它会失败,因为你没有定义提示变量。
注意你实际上不需要一个提示变量(因为
提示词永远不会改变),你可以说
....和(猜测!="提示")
而(猜测!=正确)需要与变量
进行比较,因为正确的确会改变。
print"抱歉,那不是它。
guess = raw_input("你的猜测:")
guess = guess.lower()
###我不知道如何设置这个部分是正确的,这样当他们要求提示时它会给他们###
而word == easy:
这里同样的问题,容易变量(你还没定义)。
你的意思是
而word ==easy:
如果猜= =提示:
打印不是很难,但是
guess = raw_input("你的猜测:")
guess = guess.lower()
而word == python:
同上。但是当你的单词列表变大时,这将变得乏味。
你应该将你的单词及其提示存储在字典中:
hints = { ''easy'':''不难但'',''python'':'''蛇''}
然后你需要一个可以打印出来的单个代码块提示
使用正确的单词查找词典中的提示。
如果猜= =提示:
打印提示[正确]
guess = raw_input("你的猜测:")
guess = guess.lower()
如果猜测==正确:
print"就是这样!你猜对了!\ n"
打印感谢您的播放。
raw_input(\ n \ n按回车键退出。 ;)
Hey guys,
I am back. Trying to expand on a program that was given in the book I am
studying.
No I am not a high school or college student. Doing this on my own. and
having way to much trouble
I am trying to add a hint section to a word jumble program.
I get a traceback error that the word in the jumble is not defined.
Can anyone help?
You have several errors.
thanks,
import random
# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed
You didn''t create a variable here. Something like
hint = "hint"
And this is the core of your problems. You are confusing a
variable name with the value assigned to it.
# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
# start the game
print \
"""
Welcome to Word Jumble!
Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type ''hint'' and Hit enter."
Here you have specifically told the user that the hint word is "hint".
guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##
It will fail because you did not define the hint variable.
Note you actually don''t need a hint variable (because the
hint word never changes), you could have said
.... and (guess != "hint")
whereas (guess != correct) needs to compare against a variable
because correct does change.
print "Sorry, that''s not it."
guess = raw_input("Your guess: ")
guess = guess.lower()
###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###
while word == easy:
Same problem here, easy is a variable (which you haven''t defined).
What you meant to say was
while word == "easy":
if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()
while word == python:
Ditto. But this is going to get tedious when your word list gets large.
You should have your words and their hints stored in a dictionary:
hints = {''easy'':''not hard but'',''python'':''snake''}
then you need just a single code block that can print the hint
by using the correct word to look up the hint in the dictionary.
if guess == hint:
print hints[correct]
guess = raw_input("Your guess: ")
guess = guess.lower()
if guess == correct:
print "That''s it! You guessed it!\n"
print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
Mensanator,
感谢您的帮助。这应该让我顺利。我很感激你的时间。
Chad
< me ******** @ aol.com>在消息中写道
news:11 ********************** @ g44g2000cwa.googlegr oups.com ...
Mensanator,
Thanks for your help. That should get me along. I appreciate your time.
Chad
<me********@aol.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Chad Everett写道:
Chad Everett wrote:
嘿伙计们,
我回来了。试图扩展我在学习的书中给出的一个项目。
不,我不是高中或大学生。这样做我自己。并且有很多麻烦
我正在尝试为一个单词jumble程序添加一个提示部分。
我得到一个跟踪错误,该单词在jumble没有定义。
任何人都可以帮忙吗?
Hey guys,
I am back. Trying to expand on a program that was given in the book I
am
studying.
No I am not a high school or college student. Doing this on my own. and
having way to much trouble
I am trying to add a hint section to a word jumble program.
I get a traceback error that the word in the jumble is not defined.
Can anyone help?
你有几个错误。
You have several errors.
谢谢,
import random
#创建一系列单词可供选择
WORDS =(" python",easy)
#从序列中随机选择一个单词
word = random.choice(WORDS)
#创建一个变量,以便稍后用来查看猜测是否正确
correct = word
#create变量用于提示如果需要
thanks,
import random
# create a sequence of words to choose from
WORDS = ("python", "easy")
# pick one word randomly from the sequence
word = random.choice(WORDS)
# create a variable to use later to see if the guess is correct
correct = word
# create variable to use for hint if needed
你在这里没有创建变量。像
hint =" hint"
这就是你问题的核心。你混淆了一个变量名和分配给它的值。
You didn''t create a variable here. Something like
hint = "hint"
And this is the core of your problems. You are confusing a
variable name with the value assigned to it.
#创建一个混乱版本的单词
jumble ="" ;
而单词:
position = random.randrange(len(word))
jumble + = word [position]
word = word [:position] + word [(位置+ 1):]
#开始游戏
打印\
"""
欢迎来到Word Jumble!
>解读字母以表达一个单词。
(在提示符下按回车键退出。)
"""
print" jumble is:,jumble
print"如果你需要一个提示类型''提示''并点击输入。
# create a jumbled version of the word
jumble =""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
# start the game
print \
"""
Welcome to Word Jumble!
Unscramble the letters to make a word.
(Press the enter key at the prompt to quit.)
"""
print "The jumble is:", jumble
print "If you need a hint type ''hint'' and Hit enter."
在这里你明确告诉用户提示词是提示"。
Here you have specifically told the user that the hint word is "hint".
guess = raw_input(" \\\
Your guess:")
guess = guess.lower()
while(猜测!=正确)和(猜测!="")an d(猜!=提示):##不确定
关于这个##
guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != "")and (guess != hint): ##not sure
about this either##
它会失败,因为你没有定义提示变量。
注意你实际上不需要一个提示变量(因为
提示词永远不会改变),你可以说
...和(猜测!=提示)
而(猜测!=正确)需要与变量进行比较
因为正确的确会发生变化。
It will fail because you did not define the hint variable.
Note you actually don''t need a hint variable (because the
hint word never changes), you could have said
... and (guess != "hint")
whereas (guess != correct) needs to compare against a variable
because correct does change.
print"抱歉,那不是它。
guess = raw_input("你的猜测:")
guess = guess.lower()
###我不知道如何设置这个部分是正确的,这样当他们要求提示时它会给他们###
而word == easy:
print "Sorry, that''s not it."
guess = raw_input("Your guess: ")
guess = guess.lower()
###I don"t lnow how to set up this part correct so that when they ask for
the hint it will give it to them###
while word == easy:
>同样的问题,容易变量(你还没有定义)。
你想说的是
而word ==easy:
Same problem here, easy is a variable (which you haven''t defined).
What you meant to say was
while word == "easy":
如果猜= =提示:
打印不难但是
guess = raw_input("你的猜测:")
guess = guess.lower()
而word == python:
if guess == hint:
print "not hard but"
guess = raw_input("Your guess: ")
guess = guess.lower()
while word == python:
同上。但是当你的单词列表变大时,这将变得乏味。
你应该把你的单词和他们的提示存储在字典中:
提示= {''easy'':''不难,但'',''python'':'''蛇''}
然后你需要一个代码块,可以打印提示
使用正确的单词来查找字典中的暗示。
如果猜= =提示:
打印提示[正确]
guess = raw_input("你的猜测:")
guess = guess.lower()
Ditto. But this is going to get tedious when your word list gets large.
You should have your words and their hints stored in a dictionary:
hints = {''easy'':''not hard but'',''python'':''snake''}
then you need just a single code block that can print the hint
by using the correct word to look up the hint in the dictionary.
if guess == hint:
print hints[correct]
guess = raw_input("Your guess: ")
guess = guess.lower()
如果猜测==正确:
打印那就是它!你猜对了!\ n"
打印感谢您的播放。
raw_input(\ n \ n按回车键退出。 ;)
if guess == correct:
print "That''s it! You guessed it!\n"
print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
这篇关于newb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!