菜鸟给女儿写了一个小程序,求大虾帮忙简化并发布下,谢谢!
女儿100以内加减法练习用的# -*- coding: utf-8 -*-
"""
Created on Wed Feb 11 20:53:59 2015
@author: lenovo
"""
import random
print u'100以内加减法练习 O(∩_∩)O 开始'
while 1:
number1 = random.randint(1,99)
limt2 = 99 - number1
number2 = random.randint(1,limt2)
choice = random.randint(5,6)
if choice == 5:
my_sum = number1 + number2
key = 1
while key:
your_sum = raw_input(str(number1) + ' + ' + str(number2) + '=')
# print type(your_sum)
# print type(my_sum)
if my_sum == int(your_sum) :
print u'你答对啦O(∩_∩)O哈哈~:'
print str(number1) + '+' + str(number2) + ' = ' + str(your_sum)
print ' '
print u'继续下一道题:'
key = 0
else:
print u'回答错误~~~~(>_<)~~~~ 请重新输入!'
elif choice == 6:
if number1 < number2 :
numb_temp = number2
number2 = number1
number1 = numb_temp
else:
pass
my_subtr =number1 - number2 #subtraction减法
key = 1
while key:
your_subtr = raw_input(str(number1) + ' - ' + str(number2) + '=')
# print type(your_sum)
# print type(my_sum)
if my_subtr == int(your_subtr) :
print u'你答对啦O(∩_∩)O哈哈~:'
print str(number1) + '-' + str(number2) + ' = ' + str(your_subtr)
print ' '
print u'继续下一道:'
key = 0
else:
print u'回答错误~~~~(>_<)~~~~ 请重新输入!'
没太多问题,可以升级,建议用图像界面,GUI easygui:lol: 本帖最后由 chobit 于 2015-2-12 17:39 编辑
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 11 20:53:59 2015
@author: lenovo
Edit on Wed Feb 12 16:21:28 2015
Python-version: 3.4
@editor: chobit
"""
import random
print ('100以内加减法练习 O(∩_∩)O 开始')
def randints(a = 0, b = 100):
return random.randint(a, b)
def runs(numbers, choices):
if choice:
my_result = numbers + numbers
fuhao = '+'
else:
numbers.sort(reverse=True)
my_result = numbers - numbers
fuhao = '-'
while 1:
your_result = input('%d %s %d = ' % (numbers, fuhao, numbers))
if my_result == int(your_result) :
print ('你答对啦O(∩_∩)O哈哈~:')
print ('%d %s %d = %d' % (numbers, fuhao, numbers, int(your_result)))
print ('\n继续下一道题:')
break
else:
print ('回答错误~~~~(>_<)~~~~ 请重新输入!')
while 1:
number =
choice = randints(0, 1)
runs(number, choice)
#coding: utf-8
import random
signs = '+-'
print '欢迎进入1-100加减法练习^_^'
while True:
(number_1, sign, number_2) = (random.randrange(1, 101), ramdom.sample(signs, 1), random.randrange(1, 101))
if eval('%d%s%d' % (number_1, sign, number_2)) == int(raw_input('%d %s %d = ' % (number_1, sign, number_2))):
print '答对了'
else:
print '答错了' #coding: utf-8
import random
signs = '+-'
print '欢迎进入1-100加减法练习^_^'
def input_number(number_1, sign, number_2):
return int(raw_input('%d %s %d = ' % (number_1, sign, number_2)))
while True:
(number_1, sign, number_2) = (random.randrange(1, 101), ramdom.sample(signs, 1), random.randrange(1, 101))
(true_answer, your_answer) = (eval('%d%s%d' % (number_1, sign, number_2), input_number(number_1, sign, number_2))
while your_answer != true_number:
print '答错了, 再试一次'
your_answer = input_number(number_1, sign, number_2)
print '答对了, 进入下一题' {:1_1:} # -*- coding: utf-8 -*-
from __future__ import division
"""
Created on Wed Feb 11 20:53:59 2015
@author: lenovo
"""
import random
print u'100以内加减乘除法练习 O(∩_∩)O 开始'
def panduan(a,b):
if a>b:
return a,b
else:
temp=a
a=b
b=temp
return a,b
#判断两个随机数的大小,并返回列表。
def lianxi():
x=random.randint(1,99)
y=random.randint(1,99)
z=random.choice('+-*/')
if z=='+':
print '%d + %d ='%(x,y)
daan=int(raw_input('请输入正确的答案:'))
answer=x+y
if daan==answer:
print '恭喜你,回答正确'
else:
print '回答错误。正确答案是:%d'%answer
elif z=='-':
p=panduan(x,y)
x=p
y=p
print '%d - %d ='%(x,y)
daan=int(raw_input('请输入正确的答案:'))
answer=x-y
if daan==answer:
print '恭喜你,回答正确'
else:
print '回答错误。正确答案是:%d'%answer
elif z=='*':
print '%d * %d ='%(x,y)
daan=int(raw_input('请输入正确的答案:'))
answer=x*y
if daan==answer:
print '恭喜你,回答正确'
else:
print '回答错误。正确答案是:%d'%answer
else:
p=panduan(x,y)
x=p
y=p
print '%d / %d ='%(x,y)
daan=float(raw_input('请输入正确的答案:'))
answer=x/y
if round(daan,2)==round(answer,2):
print '恭喜你,回答正确'
else:
print '回答错误。正确答案是:%s'%str(round(answer,2))
while True:
lianxi()
chobit 发表于 2015-2-12 17:28
感谢! 戴宇轩 发表于 2015-2-12 18:06
感谢,这段程序太高级了,呵呵。 wdmcwfnh 发表于 2015-2-27 15:03
您给扩展了,谢谢!{:5_92:} 厉害 学习了:loveliness: 本帖最后由 wei_Y 于 2015-3-13 12:13 编辑
用的3.4。input改成raw_input应该就好了。
能过关的话兴趣应该会大一些。(虽然不是那么好玩- -。。)
仅供参考。
import random
level = input('选择初始难度: 1.简单 2.普通 3.高难 4.凶残 5+.???:')
neg = input('选择是否开启负数模式: 1.开启 2.关闭')
score = 0
level_cur = level
while 1:
print('每题答对得%s分。答错或乱填扣%s分。分数%d可以进入下一关,' % (level_cur, level_cur, 50*int(level_cur)))
while score < 50*int(level_cur):
question = '%d'%(random.randint(1, 100))
for i in range(1, int(level_cur)+1):
question = question + str(random.choice(['+', '-']))+str(random.randint(1, 100))
if eval(question) < 0 and neg == '2':
continue
answer = input('问题'+question+'\n答案:')
if answer == str(eval(question)):
score += int(level_cur)
print('答对咯~加%s分,目前共%s分。'%(level_cur, score))
else:
score -= int(level_cur)
print('答错啦~扣%s分,目前共%s分。'%(level_cur, score))
else:
print('恭喜过关。难度加大。')
level_cur = str(int(level_cur)+1)
学习了 wei_Y 发表于 2015-3-13 12:10
用的3.4。input改成raw_input应该就好了。
能过关的话兴趣应该会大一些。(虽然不是那么好玩- -。。)
仅供 ...
厉害!!!这算法这思路,一看就是专家!!! aran 发表于 2015-3-13 15:46
厉害!!!这算法这思路,一看就是专家!!!
{:5_96:}小菜。。 支持楼主 学习了 wei_Y 发表于 2015-3-13 12:10
用的3.4。input改成raw_input应该就好了。
能过关的话兴趣应该会大一些。(虽然不是那么好玩- -。。)
仅供 ...
高高高手
{:1_1:}
谢谢前辈抄一下下
页:
[1]