1樓:雙庚的乳酪
import random
def perform_t(a, b):
rate = float(b)
if a == 0:
for i in range(num):
x = random.randint(0,10)
y = random.randint(0,10)
z = x + y
print x, '+', y, '=',
z0 = int(raw_input())
if z0 != z:
print 'incorrect - the answer is', z
rate = rate - 1
elif a == 1:
for i in range(num):
x = random.randint(0,10)
y = random.randint(0,10)
z = x * y
print x, '*', y, '=',
z0 = int(raw_input())
if z0 != z:
print 'incorrect - the answer is', z
rate = rate - 1
return rate
print 'welcome to addition / multiplication test'
print '\nhow mant questions would you like to be tested on?'
print 'enter a non negative integer for the answer:',
num = int(raw_input())
if num == 0:
print 'goodbye'
else:
print 'this software tests you with', num, 'questions ......'
print '0) addition'
print '1) multiplication'
print 'please make a selection(0 or 1):',
aorm = int(raw_input())
print 'please give the answers to the folloing addition:'
rate = perform_t(aorm, num)
if rate/num >= 0.8:
print 'well done'
elif rate/num < 0.6:
print 'please study more'
else:
print 'not too bad'
以後作業最好自己多想想。
2樓:
print '''welcome to addition / mutiplication test
how many questions would you like to be tested on?'''
amount=input('enter a non negative integer for the answer: ')
print 'this software tests you with '+str(amount)+' questions __'
print '''0) addition
1) multiplication'''
selection=input('please make a selection (0 or 1): ')
print 'please give the answers to the following mutiplications: '
import random
questions={}
def createadd(s,a):
for i in xrange(a):
first=random.randint(0,100)
second=random.randint(0,100)
# print first,second
if s==0:
result=first+second
questions[str(first)+' + '+str(second)+' = ']=result
elif s==1:
result=first*second
questions[str(first)+' * '+str(second)+' = ']=result
createadd(selection,amount)
right=0
for i in questions.keys():
got=input(i)
if got==questions[i]:
right+=1
else:
print 'incorrect - the answer is '+str(questions[i])
if right*1.0/amount>=0.8:
print 'well done'
elif right*1.0/amount>=0.6:
print 'not too bad'
else:
print 'please study more'
3樓:可靠的我心我在
python求助 現在要寫一個加法和乘法的程式, 最開始def perform_test(a,b)
4樓:ldx小童鞋
#coding:gbk
from random import randintdef perform_test(a, b):
""":param a: 1 加法 0 乘法:param b: 題目數量
:return: 正確率
"""right_count = 0
if b == 0:
return 0
for i in range(b):
x = randint(0, 100) #範圍自己定y = randint(0, 100)
if a == 0:
try:
z = input("%d * %d = "%(x, y))if z == x * y:
right_count += 1
except exception, e:
pass
elif a == 1:
try:
z = input("%d + %d = "%(x, y))if z == x + y:
right_count += 1
except exception, e:
pass
return float(right_count) / bdef choose():
try:
b = input("total count:")if b == 0:
print "goodbye"
return
a = input("add(1)/mul(0):")if a != 0 and a != 1:
print "must be 0 or 1."
return
except nameerror, e:
print e.args
except exception, e:
print e.args
ret = perform_test(a, b)if ret >= 0.8:
print "well done."
elif ret >= 0.6 and ret < 0.8:
print "not too bad."
else:
print "please study more."
if __name__ == "__main__":
print "welcome"
choose()
隨便寫了個, 你看看是不是你要的。
還得求問大神python的問題,問大神們,python問題,跪求大神解答
newarray for rid,row in enumerate oldarray newrow cid,data for cid,data in enumerate row newrow.sort key lambda x x 1 reverse true 10 newarray rid dic...
python,求大佬請教,一個python,求大佬請教
參考 usr bin python coding utf 8 from collections import defaultdict def find max letter count word matches defaultdict int makes the default value 0 fo...
python求s a aa aaa aaaa aa a的值,其中a是數字
解答du過程如圖所示 python在執行zhi時dao,首先會將.py檔案中的回源 編譯成python的byte code 位元組碼 然 答後再由python virtual machine python虛擬機器 來執行這些編譯好的byte code。題目 求bais a aa aaa aaaa a...