gpt4 book ai didi

python - 在导入函数 python 中使用用户生成的变量

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:14 25 4
gpt4 key购买 nike

我不知道该怎么调用它,所以我只是解释一下我需要做什么

假设我有以下脚本来获取用户输入:

#test0.py

import functions

number = input('pick a number')
functions.dothis()

还有这个:

#functions.py
def dothis():
global number
if number == 1:
print('the number is 1')
else:
print('the number is not one')

这显然是射出的'number' is not defined

如何通过number进入dothis()功能还是我完全以错误的方式处理这个问题?

干杯!

最佳答案

只需将其作为参数传递,如下所示:

def dothis(number): 
if number == 1:
...

number = input('pick a number')
functions.dothis(number)

关于python - 在导入函数 python 中使用用户生成的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com