-5
from random import randint
import random
from time import sleep
a = 'circle'
b = 'website'
c = 'parallel'
d = 'purple'
e = 'picture'
f = 'professional'
g = 'hospital'
h = 'complex'
i = 'helicopter'
j = 'airport'
k = 'programer'
l = 'attachment'
m = 'python'
n = 'wireless'
o = 'spouse'
p = 'desktop'
az=randint(1,16)
zz=1
score=10
aa=list(a)
print "Welcome to Josh Azrin's word game! I will give you a scrambled word."
print "If you get the word right you get 10 points. If not than you lose 2 points. You start out with 10 points."
moo = raw_input("Are you Ready? : ")
print"Here is your first scrambled word."
sleep(1.5)
while az == 1:
    print " "
    print(''.join(random.sample(a,len(a))))
    print " "
    info = raw_input(": ")
    if info == a:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)

...................................................

while az == 2:
    print " "
    print(''.join(random.sample(b,len(b))))
    print " "
    info = raw_input(": ")
    if info == b:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 3:
    print " "
    print(''.join(random.sample(c,len(c))))
    print " "
    info = raw_input(": ")
    if info == c:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 4:
    print " "
    print(''.join(random.sample(d,len(d))))
    print " "
    info = raw_input(": ")
    if info == d:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 5:
    print " "
    print(''.join(random.sample(e,len(e))))
    print " "
    info = raw_input(": ")
    if info == e:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 6:
    print " "
    print(''.join(random.sample(f,len(f))))
    print " "
    info = raw_input(": ")
    if info == f:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 7:
    print " "
    print(''.join(random.sample(g,len(g))))
    print " "
    info = raw_input(": ")
    if info == g:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 8:
    print " "
    print(''.join(random.sample(h,len(h))))
    print " "
    info = raw_input(": ")
    if info == h:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 9:
    print " "
    print(''.join(random.sample(i,len(i))))
    print " "
    info = raw_input(": ")
    if info == i:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 10:
    print " "
    print(''.join(random.sample(j,len(j))))
    print " "
    info = raw_input(": ")
    if info == j:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 11:
    print " "
    print(''.join(random.sample(k,len(k))))
    print " "
    info = raw_input(": ")
    if info == k:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 12:
    print " "
    print(''.join(random.sample(l,len(l))))
    print " "
    info = raw_input(": ")
    if info == l:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 13:
    print " "
    print(''.join(random.sample(m,len(m))))
    print " "
    info = raw_input(": ")
    if info == m:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 14:
    print " "
    print(''.join(random.sample(n,len(n))))
    print " "
    info = raw_input(": ")
    if info == n:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 15:
    print " "
    print(''.join(random.sample(o,len(o))))
    print " "
    info = raw_input(": ")
    if info == o:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 16:
    print " "
    print(''.join(random.sample(p,len(p))))
    print " "
    info = raw_input(": ")
    if info == p:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 17:
    print " "
    print(''.join(random.sample(q,len(q))))
    print " "
    info = raw_input(": ")
    if info == q:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 18:
    print " "
    print(''.join(random.sample(r,len(r))))
    print " "
    info = raw_input(": ")
    if info == r:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 19:
    print " "
    print(''.join(random.sample(s,len(s))))
    print " "
    info = raw_input(": ")
    if info == s:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)
while az == 20:
    print " "
    print(''.join(random.sample(t,len(t))))
    print " "
    info = raw_input(": ")
    if info == t:
        sleep(1)
        print "Nice job. You just earned 10 points! Your score is"
        sleep(1)
        score+10
        print score
        az=randint(1,16)
    else:
        print " "
        print "Nice try. You just lost 2 points. Please try agian."
        print "Your score is"
        sleep(1)
        score - 2
        print score
        sleep(1)

我该怎么做才能使计分器工作?我搞砸了一吨,不管它保持在10...

4

2 回答 2

2

您实际上需要重新分配分数的值。

score = score+10不是score+10

简单地说score+10不会修改score变量。


顺便说一句,您的代码还有很多其他问题。

  1. 由于您没有循环,因此while语句不适用于测试选择了哪个数字。你应该使用一个if语句。
  2. 绝对没有理由,而且它使您的代码几乎不可读,连续有 20 个while(或if)语句。您应该找到一种方法来制作一个概括每种情况的函数。
  3. 为什么你sleep到处都有声明?
  4. 您只有 16 个可能的选择,但您要测试多达 20 个
  5. 最好尽可能避免硬编码,如random(1,16).
于 2013-01-11T19:28:40.147 回答
0

而不是使用score + 10orscore - 3使用score = score + 10or score = score - 3。score + 10 只是将 score 加 10 的值相加。它不会改变 score 的值。

于 2013-01-11T19:57:44.453 回答