2013-02-21 51 views
-7

这是我正在处理的问题。我一共编程了9天,所以我很新。我试图编写一个函数来生成-1,200到1,200之间的随机整数,并返回一个依赖于数字的语句。这些陈述是:生成的数字:大于800,返回'Heidi wins'/小于或等于800,并且是偶数,返回'Magic wins'。 /小于或等于800,并以3结束,返回'Tally wins'。 /小于或等于800,并以5结束,'切尔西赢'。否则,打印'大女孩赢'。这是我的计划到目前为止:请帮助完成它。谢谢。Python编程

def sillyGame(n): 
    mychoices=[ 
    number=random.choice(myChoices) 
    inputNum=raw_input("Enter a number:") 

    numbers=['0','1','2','3','4','5','6','7','8','9','.'] 
    isValidNumber=True 
    for ch in inputNum: 
     for element in numbers: 
      isMatch=False 
      if ch ==element: 
       isMatch=True 
       break 
      if isMatch==False: 
       isValidNumber==False 
       break 
      if isValidNumber==True: 
       print("this is a valid number") 
      else: 
       print("this is not a valid number") 
+7

你的标题有点太具体。你能更模糊吗? – 2013-02-21 02:27:12

+2

您需要将此短语作为问题而不是调试请求。 – BlackVegetable 2013-02-21 02:27:20

+3

那么......真正的问题是什么?我们不能仅仅因为你的“完成”你必须告诉我们问题是什么。 – Makoto 2013-02-21 02:27:56

回答

1

如果你的问题是,你在你的注释说明,然后...

要检测x小于800: if x < 800

要检测x是偶数: if x % 2 == 0

为了检测如果x在3终止: str(x)[-1] == "3"

而任意组合使用关键字orandif x < 800 and x % 2 == 0:

希望有所帮助。