我的函数在输出中继续生成单词“none”

问题描述 投票:-3回答:1

我是初学者计算机科学课,对于我的最终,我必须使用我们所教授的基本技术创建一个包含我以前所有编码任务的菜单。我创建了一个有效的代码,但问题是我的代码在输出中也生成了“none”这个单词。

def options():  
    print ("Pick from the list")
    print ("1. Grade Conversion")
    print ("2. Temperature Conversion")
    print ("3. Currency Conversion")
    print ("4. Sum and Average")
    print ("5. Heads or Tails Guessing Game")
    print ("6. Fibonacci Sequence")
    print ("7. Factorials")
    print ("8. Multiplication Table")
    print ("9. Guess the Number Game")
    print ("10. Calculator")
    print ("11. Exit")

def Student_A_Gets_A():
    print ("Student A gets Grade A")
    print (Score)
def Student_B_Gets_B():
    print ("Student B gets Grade B")  
    print (Score)
def Student_C_Gets_C():
    print ("Student C gets Grade C")
    print (Score)
def Student_D_Gets_D():
    print ("Student D gets Grade D")
    print (Score)
def Student_F_Gets_F():
    print ("Student F gets Grade F")   
    print (Score)

def Celsius():
    Temperature = int(input ("Please enter Temp. in Celsius: "))
    print ("Fahrenheit = ", (Temperature*(9/5))+32)
def Fahrenheit():
    Temperature = int(input ("Please enter Temp. in Fahrenheit: "))
    print ("Celsius = ", (Temperature-32)*(5/9))

def Currency_Conversion():
    print ("Pick from the list")
    print ("1. Dollar to Euro")
    print ("2. Dollar to Peso")
    print ("3. Euro to Dollar")
    print ("4. Peso to Dollar")
    print ("5. Euro to Peso")
    print ("6. Peso to Euro")

def Dollar_to_Euro():
    print ("You have selected 1 to convert Dollar to Euro")
    Amount = int(input("Please enter the amount in dollar(s): "))
    print ("$", Amount, " = ", "€",(Amount)*(0.813654))
def Dollar_to_Peso():
    print ("You have selected 2 to convert Dollar to Peso")
    Amount = int(input("Please enter the amount in dollar(s): "))
    print ("$", Amount, " = ", "Mex$",(Amount)*(18.695653))
def Euro_to_Dollar():
    print ("You have selected 3 to convert Euro to Dollar")
    Amount = int(input("Please enter the amount in euro(s): "))
    print ("€", Amount, " = ", "$",(Amount)/(0.813654))
def Peso_to_Dollar():
    print ("You have selected 4 to convert Peso to Dollar")
    Amount = int(input("Please enter the amount in peso(s): "))
    print ("Mex$", Amount, " = ", "$",(Amount)/(18.695653))
def Euro_to_Peso():
    print ("You have selected 5 to convert Euro to Peso")
    Amount = int(input("Please enter the amount in euro(s): "))
    print ("€", Amount, " = ", "Mex$",(Amount)*(22.98))
def Peso_to_Euro():
    print ("You have selected 6 to convert Peso to Euro")
    Amount = int(input("Please enter the amount in peso(s): "))
    print ("$", Amount, " = ", "€",(Amount)/(22.98))


def options2 ():    
    print ("Select Operation")
    print ("1. Add 2 numbers")
    print ("2. Subtract 2 numbers")
    print ("3. Multiply 2 numbers")
    print ("4. Divide 2 numbers")
    print ("5. Guessing Game")


print (options())
answer = int(input("Enter a choice from 1 through 10: "))
while (1):
    if answer < 1 and answer > 11:
        print ("Sorry, that is not an option. Enter a number from 1 through 11")
        print (" ")
        print (options())
        answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 1:
        Score = int(input("Please enter Score: "))
        if Score >= 90 and Score <= 100:
            print (Student_A_Gets_A())
            print (" ")
            print (options ())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Score >= 80 and Score <= 89:
            print (Student_B_Gets_B())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Score >= 70 and Score <= 79:
            print (Student_C_Gets_C())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Score >= 60 and Score <= 69:
            print (Student_D_Gets_D())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Score >= 50 and Score <= 59:
            print (Student_F_Gets_F())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        else:   
            print ("Error: Score must be between 100 and 50 for grades A through F")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 2:
        Celsius_or_Fahrenheit = int(input ("Please enter 1 for Celsius or 2 for Fahrenheit: "))
        if Celsius_or_Fahrenheit == 1:
            print (Celsius())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Celsius_or_Fahrenheit == 2:
            print (Fahrenheit())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        else:
            print ("Error, must choose 1 for Celsius or 2 for Fahrenheit")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 3:
        print (Currency_Conversion())
        Currency_Conversion_answer = int(input("Enter a choice from 1 through 6: "))
        if Currency_Conversion_answer == 1:
            print (Dollar_to_Euro())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Currency_Conversion_answer == 2:
            print (Dollar_to_Peso())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Currency_Conversion_answer == 3:
            print (Euro_to_Dollar())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Currency_Conversion_answer == 4:
            print (Peso_to_Dollar())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Currency_Conversion_answer == 5:
            print (Euro_to_Peso())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif Currency_Conversion_answer == 6:
            print (Peso_to_Euro())
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        else:
            print ("Error, number not within bounds")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 4:
        number = int(input("How many numbers would you like to add: "))
        counter = 0
        average = 0
        for j in range(1,number+1):
            if j %10 == 0:
                print (j,",")
            elif j == number:
                print (j)
            else:
                print (j,"," ,end="")
        for i in range(1,number + 1):
            counter += i
            average = counter/number
        print ("sum = ", counter)
        print ("average = ", average)
        print (" ")
        print (options())
        answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 5:
        import random
        rand = random.randint(1,2)
        guess = int(input("Guess Heads(1) OR Tails(2): "))
        if guess is 1 or guess is 2 and guess is rand:
            print ("You win")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif guess is 1 or guess is 2 and guess is not rand:
            print ("You lose")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        else:
            print ("Error, number must be 1 or 2")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 6:
        fib = int(input("How many Fibonacci numbers shall I generate? "))
        x = 1
        y = 1
        print ("Fibonacci sequence up to", fib)
        for i in range (1):
            for i in range (1,fib+1):
                x = y - x
                y = x + y
                if i %10 == 0 and i is not fib:
                    print (x, ", ")
                elif i == fib:
                    print (x)
                else:
                    print (x, ", ", end="")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 7:
        Number = int(input("Factorial of what number do you want? Number must be less than or equal to 20. "))
        if Number > 20:
            print ("Error")
        else:
            Factorial = 1 
            for i in range(1,Number + 1):
                print (i,)
                Factorial = Factorial * i
            print("Factorial of", Number, " is ",Factorial)
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 8:
        num = int(input("Enter multiplication table you want to see: "))
        maximum = int(input("Enter max you want your table to go to: "))
        counter = 0
        print ("The table of", num)
        for i in range (0,maximum):
            counter = i + 1
            print (counter, "*", num, "=", counter*num)
        print ("Done counting...")
        print (" ")
        print (options())
        answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 9:
        import random
        number = int(input("Guess any number 1 to 10? "))
        guess = random.randint(1,10)
        acc = 0
        while guess > 0:
            if guess < number:
                print ("Too High")
                number = int(input("Guess any number 1 to 10? "))
                acc+=1
            elif guess > number:
                print ("Too Low")
                number = int(input("Guess any number 1 to 10? "))
                acc+=1
            elif guess == number:
                acc+=1
                break
        print ("And it only took you", acc, "tries")
        print (" ")
        print (options())
        answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 10:
        import random
        rand = random.randint(1,4)
        print (options2())
        answer = int(input("Enter a choice from 1 through 5: "))
        if answer > 5 and answer < 1:
            print ("Sorry, that is not an option")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif answer == 1:
            x=float(input("Please enter the first number: "))
            y=float(input("Please enter the second number: "))
            print (x,"+",y,"=",x+y)
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif answer == 2:
            x=float(input("Please enter the first number: "))
            y=float(input("Please enter the second number: "))
            print (x,"-",y,"=",x-y)
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif answer == 3:
            x=float(input("Please enter the first number: "))
            y=float(input("Please enter the second number: "))
            print (x,"*",y,"=",x*y)
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
        elif answer == 4:
            x=float(input("Please enter the first number: "))
            y=float(input("Please enter the second number: "))
            if y == 0:
                print ("Error, denominator cannot be zero")
                print (" ")
                print (options())
                answer = int(input("Enter a choice from 1 through 11: "))
            else:
                print (x,"/",y,"=",x/y)
        elif answer == 5:
            x=float(input("Please enter the first number: "))
            y=float(input("Please enter the second number: "))
            if rand == 1:
                print (x,"+",y,"=",x+y)
                print (" ")
                print (options())
                answer = int(input("Enter a choice from 1 through 11: "))
            elif rand == 2:
                print (x,"-",y,"=",x-y)
                print (" ")
                print (options())
                answer = int(input("Enter a choice from 1 through 11: "))
            elif rand == 3:
                print (x,"*",y,"=",x*y)
                print (" ")
                print (options())
                answer = int(input("Enter a choice from 1 through 11: "))
            elif rand == 4:
                print (x,"/",y,"=",x/y)
                print (" ")
                print (options())
                answer = int(input("Enter a choice from 1 through 11: "))
        else:
            print ("Error, must choose from the aforementioned selections")
            print (" ")
            print (options())
            answer = int(input("Enter a choice from 1 through 11: "))
    elif answer == 11:
        break
print ("You have exited")
python python-3.x
1个回答
2
投票

打印函数的返回值,如@Patrick Haugh所示。例如,第82行:

print (options())

运行options()函数,它打印出替代品,然后从options()打印返回值,这是None,因为你没有指定任何返回值。而是将代码行82作为:

options()

你需要在很多地方纠正这个问题,然后对其他功能进行纠正,例如: Celsius()

© www.soinside.com 2019 - 2024. All rights reserved.