Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

cs50p little professor question, my code get rejected because of wrong level . anyone knows why?

$
0
0

this is my code for the little professor problem , the task is when the level is not 1 ,2 or 3 repromt , this is what the code does but still get reject for the level repromt

:) professor.py exists:( Little Professor rejects level of 0    expected program to reject input, but it did not:( Little Professor rejects level of 4    expected program to reject input, but it did not:( Little Professor rejects level of "one"    expected program to reject input, but it did not:) Little Professor accepts valid level:) At Level 1, Little Professor generates addition problems using 0–9:) At Level 2, Little Professor generates addition problems using 10–99:) At Level 3, Little Professor generates addition problems using 100–999:) Little Professor generates 10 problems before exiting:) Little Professor displays number of problems correct:) Little Professor displays EEE when answer is incorrect:) Little Professor shows solution after 3 incorrect attempts
import randomdef main():    while True:        level = get_level()        if level.isdigit() and int(level) in [1, 2, 3]:            break        else:            ...    score = 0    valid = False    for i in range(10):        tries = 3        valid = False        intOne = generate_integer(level)        intTwo = generate_integer(level)        ans = input(str(intOne) +" +" + str(intTwo) +" = ")        while not valid:            res = intOne + intTwo            if int(ans) != res:                tries -= 1                if tries == 0:                    valid = True                    print(str(res))                else:a                    print('EEE')                    ans = game(intOne, intTwo)            else:                score += 1                valid = True    print(score)def get_level():    level = input('Level: ')    return leveldef game(intOne, intTwo):         ans = input( str(intOne) +" +"+ str(intTwo) +" = " )         return ansdef generate_integer(level):    if level == "2":        return random.randint(10, 99)    if level == "3":        return random.randint(100, 999)    return random.randint(0, 10)if __name__ == "__main__":    main()

Viewing all articles
Browse latest Browse all 23131

Trending Articles