要求如下:
1一女子择偶,两个男士被选择
2.如果两男存款少于100W,都不考虑
3.如果两男存款大于1000W,跟存款多的走
4.身高选择个子高的,如果个子都大于170,且相差不到5cm,看颜值(10分制)
5.低于7分的直接pass,高于7分选择颜值高的,如果颜值相差不到2,看房子
6.房子不能低于100平且价值不能少于200W,都有的话,选择价值高的
价值相差少于20W,看车子
7.车子价值不能少于50W,相差不到10W,抛硬币
8.要使用继承,传入两个对象
解题如下:
如有bug欢迎指正
import random
class People(object):
def __init__(self,money,height,yanZhi,fang,fangJiaZhi,cheJiaZhi):
self.money = money
self.height = height
self.yanZhi = yanZhi
self.fang = fang
self.fangJiaZhi = fangJiaZhi
self.cheJiaZhi = cheJiaZhi
class Nan(People):
def __init__(self,money,height,yanZhi,fang,fangJiaZhi,cheJiaZhi):
super(Nan,self).__init__(money,height,yanZhi,fang,fangJiaZhi,cheJiaZhi)
class Nv(People):
def __init__(self):
pass
def panDuan(self,other1,other2):
def paoYingBi():
num = random.randint(0, 1)
return num
# 都小于100万
if other2.money <1000000 and other1.money <1000000 :
print('都不考虑')
return
# 有一个人大于1000万
elif other2.money >=10000000 or other1.money >=10000000 :
if other1.money >other2.money:
print('选男1')
elif other2.money > other1.money:
print('选男2')
# 男2小于100万
elif other2.money < 1000000 and other1.money >=1000000:
print('选男1')
# 男1小于100万
elif other1.money <1000000 and other2.money >=1000000:
print('选男2')
# 男1和男2都大于100万小于1000万
elif other1.money >= 1000000 and other2.money>=1000000:
# 身高都大于170cm
if other1.height >170 and other2.height >170:
# 身高相差不到5cm
if other1.height - other2.height <5 or other2.height - other1.height <5:
if other1.yanZhi <7 and other2.yanZhi <7:
print('颜值太低,都不考虑')
return
elif other1.yanZhi <7:
print('我是一个颜值控,我选男2')
elif other2.yanZhi <7:
print('我是一个颜值控,我选男1')
# 颜值都大于7
if other1.yanZhi >=7 and other2.yanZhi>=7:
# 颜值相差不到2
if other1.yanZhi - other2.yanZhi <2 and other2.yanZhi - other1.yanZhi <2:
if other1.fang < 100 and other1.fangJiaZhi < 2000000 :
if other2.fang < 100 and other1.fangJiaZhi < 2000000:
print('房子都不行,都不考虑')
return
else:
print('男1房子不行,不考虑','\n','选男2')
return
if other2.fang <100 or other2.fangJiaZhi <2000000:
print('男2房子不行,不考虑','\n','选男1')
return
else:
# 房子价值相差不到200万
if 0<other1.fangJiaZhi - other2.fangJiaZhi <2000000 or 0<other2.fangJiaZhi - other1.fangJiaZhi <2000000:
# 车子价值大于50万
if other1.cheJiaZhi >= 500000 or other2.cheJiaZhi >=500000:
# 车子价值相差不到10万
if 0<other1.cheJiaZhi - other2.cheJiaZhi <100000 or 0<other2.cheJiaZhi-other1.cheJiaZhi<100000:
num = paoYingBi()
if num ==0:
print('抛硬币结果:选男1')
elif num == 1:
print('抛硬币结果:选男2')
# 车子价值相差大于10万
else:
if other1.cheJiaZhi>other2.cheJiaZhi:
print('选男1')
else:
print('选男2')
else:
print('车子价值太低,不考虑')
# 房子价值相差超过20万
elif other1.fangJiaZhi - other2.fangJiaZhi >=200000 or other2.fangJiaZhi - other1.fangJiaZhi >=200000:
if other1.fangJiaZhi > other2.fangJiaZhi:
print('我对房子要求有点高,我选男1')
elif other1.fangJiaZhi < other2.fangJiaZhi:
print('我对房子要求有点高,我选男2')
# 颜值相差超过2
else:
if other1.yanZhi>other2.yanZhi:
print('我是一个颜值控,我选男1')
elif other1.yanZhi<other2.yanZhi:
print('我是一个颜值控,我选男2')
# 身高相差超过5cm
else:
if other1.height>other2.height:
print('选男1')
else:
print('选男2')
# 身高有不大于170cm的
else:
if other1.height > other2.height:
print('选男1')
else:
print('选男2')
# 值1:存款;值2:身高;值3:颜值(十分制);值4:房子面积;值5:房子价值;值6:车子价值
nan1 = Nan(1000000,172,8,110,1000000,520000)
nan2 = Nan(1000000,175,8,120,2200000,550000)
Nv().panDuan(nan1,nan2)