-5
我有一個猜數字遊戲的代碼,當我發現問題時我正在玩它。遊戲代碼錯誤行跳 - Python
#猜數
print("I'm thinking of a number between 1 and 20. Can you guess my number?")
r = str(input('{} please enter a integer between 1 and 10: '.format(name)))
r = str(input('{} please enter a integer between 1 and 10: '.format(name2)))
print (name, ' you chose ', r)
print (name2, ' you chose ', p)
r1 = random.randrange(10)
打印誰贏得
if r == p:
print('Plz choose different numbers from each other')
if r == r1:
print('Computer chose', r1,',',name,' Wins!')
if p == r1:
print('Computer chose', r1,',',name2,' Wins!')
elif (r > 'r1' and p < 'r1'):
print('Computer chose', r1, ' both of you lose')
elif (r < 'r1' and p < 'r1'):
print('Computer chose', r1, ' both of you lose')
elif (r > 'r1' and p > 'r1'):
print('Computer chose', r1, ' both of you lose')
elif (r < 'r1' and p > 'r1'):
print('Computer chose', r1, ' both of you lose')
當計算機讀取的代碼
if r == p:
print('Plz choose different numbers from each other')
if r == r1:
print('Computer chose', r1,',',name,' Wins!')
if p == r1:
print('Computer chose', r1,',',name2,' Wins!')
elif (r > 'r1' and p < 'r1'):
print('Computer chose', r1, ' both of you lose')
elif (r < 'r1' and p < 'r1'):
print('Computer chose', r1, ' both of you lose')
elif (r > 'r1' and p > 'r1'):
print('Computer chose', r1, ' both of you lose')
elif (r < 'r1' and p > 'r1'):
print('Computer chose', r1, ' both of you lose')
的這一部分它跳過了第一部分,並一直說雙方球員都輸了。爲什麼會發生這種情況,我該如何解決?
我覺得有很多問題。下面是另外一個問題:爲什麼我們要比較第一個變量'p','r'和'r1'('p == r1'),然後有時會串入'r''r1'和p>'r1'? –
@ Two-BitAlchemist是的,其實只是做了一個編輯。 – smarx
「這個詞實際上拼寫爲'輸'。」 +1 –