四则运算

#!Users/admin/Desktop
# -*- coding:utf-8 -*-
count=0
n=int(input("生成多少题?:"))
list=[]
listx=[]
listy=[]
while(count<n):
count+=1
import random
x=random.randrange(1,10)
y=random.randrange(1,10)
z=random.randrange(1,4)
if(z==1):
z="+"
fx=x+y
elif(z==2):
z="-"
fx=x-y
elif(z==3):
z="*"
fx=x*y
elif(z==4):
z="/"
fx=x/y
if(type(fx)!=int):
fx=("{}".format(x)+"/"+"{}".format(y))
formulation=("题目"+"{}".format(count)+":"+"{}".format(x)+"{}".format(z)+"{}".format(y)+"=")
print(formulation)
file=open("C:/Users/admin/Desktop/a.txt","w")
file.write(formulation)

listx.append(x)
listy.append(y)
if __name__=="__main__":
list.append(fx)
if __name__=="__main__":
print("答案:")
print(list)
global i
i=0
global j
j=0
for i in range(0,count):
if(i!=count-1):
for j in range(i+1,count):
if(list[i]==list[j] and j!=count-1):
print("题目{}".format(i+1)+"与"+"题目{}答案相同".format(j+1)+"有可能重复")
print("稍等,程序进一步检验中")
if(listx[i+1]==listy[j+1] and i<count-1 and j<count-1):
print("好尴尬,确实重复")
else:
print("不重复")
break

原文地址:https://www.cnblogs.com/dkyGreen/p/11938543.html