-1
我正在製作一個基於文本的冒險遊戲,但在某一點上,我希望用戶被無休止地鍵入數字。我非常新,Python越來越簡單越好,但這是我至今得到的。random.shuffle()不適用於數字猜謎遊戲
下面是代碼
import os
import sys
import string
import time
import random
numbers = ['1', '2', '3', '4', '5', '6', '7', '8' , '9']
print("Welcome to My Text Adventure Game: Dumb Edition")
print ("You (yes YOU) awake in an E-M-P-T-Y room.")
print ("It's very chilly willy and someone is drawing on the walls")
print (" Do you exit the room via the door that is obviously the right way (1)")
print ("what do you do?")
time.sleep(1)
print("Wait!")
print("You can't be trusted to not get this wrong")
print("I'll do it")
print("1")
time.sleep(1)
print("Erm...It should be going..")
print("Meh I'll just make something up! Two seconds..")
time.sleep(3)
print ("Ok.. I've got it! You'll just press buttons and it will be fun!")
print ("Or else..")
print ("Here we go...")
time.sleep(1)
print ("Please enter the following")
while True:
rng_number = random.shuffle(numbers)
print (rng_number)
user_input = input("Go on, type it in!")
if user_input == rng_number:
print("Good job again!")
else:
print("Try again...Moron")
下面是當我運行的代碼
Welcome to My Text Adventure Game: Dumb Edition
You (yes YOU) awake in an E-M-P-T-Y room.
It's very chilly willy and someone is drawing on the walls
Do you exit the room via the door that is obviously the right way?(1)
what do you do?
Wait!
You can't be trusted to not get this wrong
I'll do it
1
Erm...It should be going..
Meh I'll just make something up! Two seconds..
Ok.. I've got it! You'll just press buttons and it will be fun!
Or else..
Here we go...
Please enter the following
None
Go on, type it in!None
Try again...Moron
None
Go on, type it in!
請在此處添加您的代碼。 – marmeladze
首先請將您的代碼粘貼爲代碼而不是圖片。 'random.shuffle(x [,random])將[序列號]置亂[Doc](https://docs.python.org/3.4/library/random.html#random.shuffle) 換句話說,當你調用'rng_number = random.shuffle(numbers)'它只是將數組數組並且將'None'賦給'rng_number'('random.shuffle()'返回None)。並且'input'從用戶讀取文本輸入,您應該將其轉換爲int。 –
謝謝亞歷克斯。我已經改變了輸入爲int(輸入(「繼續,輸入!」)),但我仍然沒有取代一個數字。 –