1

ということでかけ算ゲームを作ってみました。それで、ちょっとうまくいきますが、正しい答えを入力すると、「間違った」と2回入力されます...間違った答えを入力した場合と同様です。

import sys #imports sys
random1=['1','2','3','4','5','6','7','8','9','10','11','12'] #makes a list with numbers 1-12
random2=['1','2','3','4','5','6','7','8','9','10','11','12'] #makes another list with numbers 1-12

from random import choice #gets a random number
while True: #makes the following code run in a loop
    print "To exit this game type 'exit'" #prints stuff
    theyputinstuffhere = raw_input("What is " + choice(random2) + " times " + choice(random1) + "? ") #asks the user things like 1*5 or some other random stuff.


    if theyputinstuffhere == "exit": #if the user typed in 'exit' then exit the game
        print "Now exiting game!" #prints stuff
        sys.exit() #exits

    elif theyputinstuffhere == int(choice(random2))*int(choice(random1)): #if what i typed is right, print stuff (I think i messed up here!)
        print "Correct!" #print stuff
    else:
       print "Wrong!" #otherwise print stuff 

何を間違えたのかわかりません HELP!!!!!!!!!!!!! 素早い!!!!!!!!!!!!!!!!!

4

4 に答える 4

0

この質問への回答は >>>>>> クリスチャン・カレガによって回答されました!!!!!

import sys 
import random

while True: 
    num1 = random.randint(0,12)
    num2 = random.randint(0,12)
    print "To exit this game type 'exit'" 
    theyputinstuffhere = raw_input("What is " + str(num2) + " times " + str(num1) + "? ") 


if theyputinstuffhere == "exit": #if the user typed in 'exit' then exit the game
    print "Now exiting game!" #prints stuff
    sys.exit() #exits

elif int(theyputinstuffhere) == num1*num2: 
    print "Correct!" #print stuff
else:
    print "Wrong!" 

皆さん、ありがとうございました!!!!あなたはすべて助けました!!! (すみませんクリスチャン、私はちょうど間違ってコピーしました...)

于 2013-06-18T22:05:53.870 に答える