调用后放置的函数不起作用

问题描述

有人知道为什么当我在调用函数后放上我的函数时,它不起作用,但是如果我把它放到它之前,它能起作用吗?

question = input("type any key to start")
if type(question == str):
    game()

def game():
    print("Rock paper or scissors")

当我将def game()放在开头时,这是行不通的。

解决方法

以这种方式重新排列代码:

def game():
    print("Rock paper or scissors")
question = input("type any key to start")
if type(question == str):
    game()

您只能在定义函数后调用