-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. while20 個(またはif) 個のステートメントを続けて使用すると、コードがほとんど読めなくなります。それぞれのケースを一般化する関数を作成する方法を考え出す必要があります。
  3. なぜsleepどこにでも声明があるのですか?
  4. 可能な選択肢は 16 しかありませんが、最大 20 までテストしています。
  5. のように、可能な限りハードコーディングを避けることをお勧めしrandom(1,16)ます。
于 2013-01-11T19:28:40.147 に答える
0

またはを使用する代わりにscore + 10またはをscore - 3使用します。score + 10 は、score に 10 を加えた値を加算するだけです。score の値は変更されません。score = score + 10score = score - 3

于 2013-01-11T19:57:44.453 に答える