我想知道在python中是否可行

时间:2016-03-08 05:52:23

标签: python while-loop

我想知道是否有可能在每次输入后按顺序显示“输入星期一,星期二,星期三等的胜利数”。我能想到的唯一方法是在模块中创建多个输入。

    // Do any additional setup after loading the view, typically from a nib.
    tableData = [
        ["title": "Gender", "height": "118", "cellID": "cell1"],
        ["title": "Componnet", "height": "205", "cellID": "cell2"],
        ["title": "Lille Attribute", "height": "905", "cellID": "cell3"],
        ["title": "Sensory Effect", "height": "215", "cellID": "cell4"],
        ["title": "Emotional Messages", "height": "338", "cellID": "cell5"],
        ["title": "Personalities", "height": "336", "cellID": "cell6"],
        ["title": "Country", "height": "97", "cellID": "cell7"],
        ["title": "Season", "height": "94", "cellID": "cell8"]
    ]
    expandSections = NSMutableArray() as [AnyObject]
    for var i = 0; i < tableData.count; ++i {
        expandSections .append(false);
    }
    tableView.registerNib(UINib(nibName: "TableViewCell1", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell1") // in this line
    tableView.registerNib(UINib(nibName: "TableViewCell2", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell2")
    tableView.registerNib(UINib(nibName: "TableViewCell3", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell3")
    tableView.registerNib(UINib(nibName: "TableViewCell4", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell4")
    tableView.registerNib(UINib(nibName: "TableViewCell5", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell5")
    tableView.registerNib(UINib(nibName: "TableViewCell6", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell6")
    tableView.registerNib(UINib(nibName: "TableViewCell7", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell7")
    tableView.registerNib(UINib(nibName: "TableViewCell8", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell8")

3 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

def getWins():
    week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
    scores = {} # Perhaps you want to return a dictionary? If not, just set this to 0 and += score below. Also, remove sum()
    for day in week:
        score = int(raw_input("Enter the number of wins on {}: ".format(day)))
        scores[day] = score
    return sum(scores.values())

getWins()
"""
>>> getWins()
Enter the number of wins on Monday: 5
Enter the number of wins on Tuesday: 4
Enter the number of wins on Wednesday: 5
Enter the number of wins on Thursday: 1
Enter the number of wins on Friday: 3
Enter the number of wins on Saturday: 7
Enter the number of wins on Sunday: 9
34
"""

答案 1 :(得分:0)

  

我能想到的唯一方法是在模块中进行多个输入

  • 在Python 2.7中,for返回一个字符串
  • 字符串可以拆分

您可以让用户在一个1; yi=interpl(x,y,0.4:0.4:3.6) 中输入整周的值,用空格,逗号等分隔。

raw_input

答案 2 :(得分:0)

您可以使用map创建用户所做的所有输入的列表:

dailywins = map(int, raw_input("enter the daily wins of whole week").split()) 
# THIS gives you a list object of ints which can be manipulated any way you want(here input is space separated)

现在你可以做到:

totalwins = sum(dailywins)

获取totalwins