Python脚本无法运行

时间:2016-08-19 09:21:09

标签: python

我写了一个代码。我把它保存为" .py"。但是当我打开它时,一个黑色的控制台来回走动。所以我看不到错误。我的代码:

import time

def average(numb1, numb2, numb3):
    while true:
        result = numb1 + numb2 + numb3
        print('The average is' + str(average) + '\n')

time.sleep(3)

def main():
    while true:
        num1 = input('Enter the first number > ')
        try:
            num1 = float(num1)
        except ValueError:
            print('Please enter a number !\n')
            continue
        num2 = input('Enter the first number > ')
        try:
            num2 = float(num2)
        except ValueError:
            print('Please enter a number !\n')
            continue
        num3 = input('Enter the first number > ')
        try:
            num3 = float(num3)
        except ValueError:
            print('Please enter a number !\n')
            continue
        average(num1, num2, numb3)

try:
    main()
except KeyboardInterrupt:
    print('\n\nKeyboard exception received. Exiting.')
    exit()
如果我解决了这个问题,我将非常高兴。谢谢!

1 个答案:

答案 0 :(得分:0)

average函数中有一个无限循环。

试试这个:

def average(numb1, numb2, numb3):
    print('The average is' + str((numb1 + numb2 + numb3)/3) + '\n')