我想用python做一個猜謎遊戲,但我的代碼似乎不工作。我只是進入Python,所以我不是最好的。這是我的代碼。代碼爲猜謎遊戲將不會打印任何東西后,我輸入我的號碼
print "Hello"
print "You have found me, haven't you?"
print "Well, since you did all the work to find me..."
print "I will let you have my diamond and gold infused microwave!"
print "But there is a twist"
print "You have to guess my favorite number! You only have one try!"
print "It is a number from 1 to 5"
guess=raw_input("What is my number?")
import random
for x in range(1):
print random.randint(1,5)
correct=random.randint
def correct_number(correct):
if correct==guess:
print "Dang! You got it!"
elif correct > guess:
print "Wrong! Too low!"
elif correct < guess:
print "Wrong! Too High!"
我需要它說「當它!你贏了!」如果你做得對,「錯!太高!」如果你的猜測太高,並且「錯誤!太低!」如果你的猜測太低。
確保正確格式化您的代碼,以便它可以很容易地閱讀:http://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks – ari 2015-02-05 22:53:28
什麼不加工? – IanAuld 2015-02-05 22:56:35
*「我的代碼似乎不起作用」* - 這是一個沒有意義的描述。什麼不行?你有錯誤嗎?如果是這樣,你的錯誤是什麼?你問你爲什麼不像你期望的那樣行事? – yuvi 2015-02-05 22:56:50