【问题标题】:How to compare 1 user given number with 6 random array number [duplicate]如何将1个用户给定数字与6个随机数组数字进行比较[重复]
【发布时间】:2020-05-14 14:42:31
【问题描述】:
    import random
    lotteryNumbers = []
    choice1=int(input('1st number:'))
    choice2=int(input('2nd number:'))
    choice3=int(input('3th number:'))
    choice4=int(input('4th number:'))
    choice5=int(input('5th number:'))
    choice6=int(input('6th number:'))
    for i in range (0,6):
      number = random.randint(1,49)
      while number in lotteryNumbers:
        number = random.randint(1,49)
      lotteryNumbers.append(number)
    print("Lottery numbers are: ") 
    print(lotteryNumbers)
    if choice1 == lotteryNumbers[0] or lotteryNumbers[1] or lotteryNumbers[2] or lotteryNumbers[3]or 
    lotteryNumbers[4]or lotteryNumbers[5]:
      print("first number: match")
    else:
      print("not match")

1.这是我的原始代码,请帮助我解决这个问题。非常感谢你

【问题讨论】:

  • 任何时候你发现自己命名变量,如choice1choice2 等,你几乎总是应该使用一个列表。

标签: python arrays if-statement random compare


【解决方案1】:

你只需要这样做

if choice in lotteryNumbers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-09
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    相关资源
    最近更新 更多