from random import randint as r
x = r(1, 100)
y = r(1, 10)
def rannum(x,y):
if (x==y):
m = 2*y
else:
z = x * y
print z
rannum(x,y)
我有随机生成的x和y值,我有一个有两个条件的函数。我怎么能构造循环来满足我的x == y条件?我怎么能多次知道家里我跑圈来满足这个条件。我对编程很新,并且坚持这一点。请建议/推荐我实现结果的方法。我已经做了较小的范围,因此选择相同数字的概率很高.Thankyou
答案 0 :(得分:0)
我不知道你为什么要这样做,但以下是我从你的问题中理解的。
from random import randint as r
def rannum(x,y):
if (x==y):
m = 2*y
print m
else:
z = x * y
print z
count=0
while True:
count=count+1
x = r(1, 100)
y = r(1, 10)
if (x==y):
print "x is equal to y after count=",count
rannum(x,y)
break