import random rand_one = int(random.randrange(1,10)) rand_two = int(random.randrange(1,10)) answer = int(rand_one) * int(rand_two) Right = 0 Wrong = 0 print "what is" , str(rand_one), "times", str(rand_two), "?" def ask_for_integer(ask): while True: reply = raw_input(ask) if not reply.isdigit(): print "Please enter a number" else: return reply def ask_for_yn(ask): while True: answer = raw_input(ask) if answer[0] <> "y" and answer[0] <> "n": print "please enter a y or n." else: return answer def play_one_game(): global right global wrong print "What is", str(rand_one), "times", str(rand_two), "?" guess = ask_for_integer("answer") if reply == answer: print "YOu rock" right +=1 else: print "You got it wrong, YOu suck", int("answer") wrong +=1 print answer
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question