2016-02-22 23 views
-1

Quiz making instructions使用ID/else語句和隨機變量/詞典/名單

測驗讓我開始了我的代碼有點

from random import randint, shuffle 

numbers = {1:'\u4e00', 2:'\u4e8c', 3:'\u4e09', 4:'\u56db', 5:'\u4e94', \ 
    6:'\u516d', 7:'\u4e03', 8:'\u516b', 9:'\u4e5d', 10:'\u5341'} 

x=randint(1,10) 



print('Welcome to our quiz on Chinese/Japanese numerals.') 

input('What is the Value of ' +numbers[x] +'?') 


if 1 == '\u4e00' : 
    print('Congratulations! Let us continue then, consider:') 
else: 
    print('Congratulations! Let us continue then, consider:') 
    input (['\u4e00', '\u4e8c', '\u4e09', '\u56db','\u4e94', \ 
    '\u516d', '\u4e03', '\u516b', '\u4e5d', '\u5341']) 
    input ('At which position is the value of ' +numbers[x] +'?') 

我在與代碼的if和else部分的問題。我已經能夠通過詢問最初的問題並插入隨機中文字符來設置測驗的開始,但是我遇到了一個問題,「錯誤的答案,____等於_____」。聲明的一部分。我如何確定用戶插入提示的內容是正確還是不正確?

+2

'如果USER_INPUT == right_answer'?除非你實際分配用戶的輸入,否則它會有點棘手,但是...... – jonrsharpe

回答

0

我如何建立什麼樣的用戶插入到該提示是正確的還是不正確

捕獲在一個變量的輸入值,並進行等值測試:

val = input('What is the Value of ' +numbers[x] +'?') 

if val == x: 
    # input is correct 

else: 
    # input is not correct