函数返回无类型值

时间:2019-04-11 02:04:31

标签: python python-3.x object nonetype

我的代码中的此功能(菜单)有问题,返回的是None,但是当我打印input(option)的值时,它会正常打印。请遵循整个代码:

菜单文件

class Menu(object):

    def __init__(self):
        pass

    def menu(self):
        print("\n|1|")
        print('Play Game\n')
        print("-=" * 30)
        print("\n|2|")
        print('Quit\n')
        option = int(input('Digit 1 to play the game \n\t\tor \nDigit 2 to quit the game'))
        print(option)
        return option

游戏文件

import menu


menu = menu.Menu()


class Game(object):
    def __init__(self):
        pass

    def numberofcards(self, value=0):
        if value > 4 and value < 30 and value % 2 == 0:
            return value
        else:
            print("""Please enter a valid number of cards to continue.The 
number should be
greater than four, less than thirty and should be an even number""")
            menu.menu()

主文件

import game
import menu

menu = menu.Menu()
game = game.Game()

a = game.numberofcards(27)
print(a)

0 个答案:

没有答案