无效的语法 ;可能很容易修复

时间:2015-03-17 01:20:33

标签: python syntax

这是我的代码中不起作用的部分。它说"您的代码中存在错误:语法无效。" 编辑:这是破坏的代码的一部分:对于范围内的i(0,len(标记)):

def histogram(data):


def getFrequency(marks):
    freqList = []
    for i in range(0,101):
        freqList.append(0)

for i in range(0, 101):
    starsList = []
    for i in range(0, data[i]):
        starsList.append("*") 
    pad
    if data[i] < 10:
        pad = " "
    elif data[i] < 100:
        stars = "" .join(starsList)
    print("%d | %s %d" %(i, starsList)






for i in range(0, len(marks)):  
    mark = marks[i]
    freqList[mark] += 1

return freqList


freq = getFrequency(marks)
mode = maximum(freq)

#print (freq)

这是代码的其余部分(在错误的部分之上)。它可能有也可能没有错误。我把它放在这里是为了相关。

import random

def bubbleSort(data):
    count = 0
    for i in range(0,len(data) - 1):
        for j in range(0, len(data) - 1):
            count += 1
            if data[j] > data[j+1]:
                #swap
                temp = data[j]
                data[j] = data[j + 1]
                data[j + 1] = temp
    print(count)
    return data

data = [5,4,3,2,1]
data = bubbleSort(data)
print(data)



def getData():

    data = []

    for i in range(0, 100):
        data.append(random.randint(0,100))
    return data




def mean(data):

    total = 0

    for i in range (0, len(data)):
        #add data[i]
        total = total + data[i]

    return total/ len(data)


def maximum(data):

    maximum = data[0]

    for i in range(0, len(data)):
        if maximum < data[i]:
            maximum = data[i]

    return maximum



def minimum(data):

    minimum = data[0]

    for i in range(0, len(data)):
        if minimum > data[i]:
            minimum = data[i]

    return minimum

#def mode(data):


marks = getData()

2 个答案:

答案 0 :(得分:0)

你只是错过了一个右括号:

print("%d | %s %d" %(i, starsList)

答案 1 :(得分:0)

您必须在打印行中添加一个括号,内部为cicle:

for i in range(0, len(marks)):
    ....
    print("%d | %s %d" %(i, starsList))