CodeHS真的很奇怪

时间:2018-10-24 01:27:53

标签: python-2.7

我在学校的计算机科学课上正在做一些CodeHS,由于某种原因,我的程序不符合评分者的标准,也许有人可以帮助我。

自动分级机正在寻找以下内容:

enter image description here

它测试的东西在这里:

enter image description here

,每个结果都会在自动分级机中返回运行时错误,但不会在控制台中返回。

这里是我的代码:

def get_letter():
    while True:
        letter = str(input("Enter a letter:\n> "))
    if letter.isupper() == True:
        print("Character must be a lowercase letter!")
        continue
    if len(letter) > 1 or len(letter) < 1:
        print("Must be 1 character!")
    elif letter.islower() == True:
        return letter
        break

def get_index():
    while True:
        try:
            index = int(input("Enter an index (-1 to quit):\n> "))
            if index == -1:
                break
            if index > len(word) or index < 0:
                print "Invalid index"
                continue
            if index <= len(word):
                global letter 
                letter = get_letter()
                return index
                break
        except ValueError:
            print "Please enter a number"
            continue



word = input("Enter a word\n> ")
words = list(word)

while True:
    try:
        indexes = get_index()
        splitword = words[:indexes] + [letter] + words[indexes +1:]
        joinedword = ''.join(splitword)
        print joinedword
    except NameError:
        break

,这里是说明: enter image description here

CodeHS课程为8.3.8字后学习

1 个答案:

答案 0 :(得分:0)

这可能为时已晚。我只是在CodeHS上提出这个问题,而自己却遇到了麻烦。但是我在其他地方找到了它,没有达到CodeHS的要求,所以我必须自己修复它。都固定了

def get_index(Inital_Word1):
    User_Input = int(input("Enter an index (-1 to quit): "))
    DexNav = len(Inital_Word1)
    while User_Input > DexNav  or User_Input<-1:
        print "Invalid index"
        User_Input = input("Enter an index (-1 to quit):")
        DexNav = len(Inital_Word1)
    return User_Input

def get_letter():
    User_Input = input("Enter a letter: ")
    DexNav = len(User_Input)
    while DexNav > 1:
        print "Must be exactly one character!"
        User_Input = input("Enter a letter: ")
        DexNav = len(User_Input)
    while User_Input.isupper():
        print "Character must be a lowercase letter!"
        User_Input = input("Enter a letter: ")
    return User_Input

def replace_at_index(User_Input, num, replacement):
    return User_Input[0:num] + replacement + User_Input[num + 1:]

for i in range(1):
    Inital_Word = input("Enter you inital word here: ")
    Index = get_index(Inital_Word)
    while Index != -1:
        Letter = get_letter()
        Inital_Word = replace_at_index(Inital_Word, Index, Letter)
        print (Inital_Word)
        Index = get_index(Inital_Word)