“得分”变量不更新,总是打印10

时间:2013-01-11 19:27:33

标签: python python-2.7

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)

我可以做些什么来让分数计数器工作?不管它停在什么地方,我都乱了几天......

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:0)

而不是使用score + 10score - 3使用score = score + 10score = score - 3。 得分+10只是加上得分加10的值。它不会改变得分的值。