import random lotter = random.randint(1,999) print(">>>>>>>>>>>>>>>>>>>>>>>") print(f"{lotter}") print("<<<<<<<<<<<<<<<<<<<<<<<") num= eval(input("Enter three guess number 111 to 999: ")) # 将随机彩票进行分解 lotter1 = lotter // 100 lotter2 = lotter % 100 // 10 lotter3 = lotter % 100 % 10 #将客户输入的数进行分析 guess1 = num // 100 guess2= num % 100 //10 guess3= num % 100 % 10 if num == lotter: print("Good luck! Your luck guest give your 100000 dollars!") elif num != lotter: print("Sorry next continu....!") elif guess1 and guess3 and guess2 == lotter1 and lotter2 and lotter3: print("Ha!Ha!,give you 3000 dollars") elif guess2 and guess3 and guess1 == lotter1 and lotter2 and lotter3: print("Ha!Ha!,give you 3000 dollars") elif guess3 and guess2 and guess1 == lotter1 and lotter2 and lotter3: print("Ha!Ha!,give you 3000 dollars") elif guess2 and guess1 and guess3 == lotter1 and lotter2 and lotter3: print("Ha!Ha!,give you 3000 dollars") elif guess3 and guess1 and guess2 == lotter1 and lotter2 and lotter3: print("Ha!Ha!,give you 3000 dollars") elif guess1 or guess2 or guess3 == lotter1 or lotter2 or lotter3: print("Woo! 1000 dollas!")请同学注意下面这段(这是修改完正确的)
if num == lotter: print("Good luck! Your luck guest give your 100000 dollars!") elif num != lotter: print("Sorry next continu....!")开始的时候我是把elif这段话放到整个程序的后面。程序和结果见下面 大家看到了吧按程序设想和彩票号不一致是应该打印 print(“Sorry next continu…!”) 但是却没有,经过今天上午第一个问题的出现。我开始考虑这个if和elif之间的关系。或者说现在考虑的是关系。 后来我将num != lotter的条件调整了位置,请看上面的正确的位置。if和elif不要分离的太远。num等于和不等于lotter这是一组if和elif。 不知道我这个问题对大家是否有帮助。多多指教。就当是抛砖引玉吧·
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)