再一次求助

编24点程序时遇到的问题
大佬好呀,Python小白又来求助啦!
这次的问题是在编24点时遇到的一个问题:如何将用户输入的数字运算出结果?
源代码:
import random
shuzi_str_one=str(random.randint(1,10))
shuzi_str_two=str(random.randint(1,10))
shuzi_str_three=str(random.randint(1,10))
shuzi_str_four=str(random.randint(1,10))
def twntyfour():
shuzi_str=shuzi_str_one+’ ‘+shuzi_str_two+’ ‘+shuzi_str_three+’ ‘+shuzi_str_four
global shuzi_str
tuntyfour()
print(‘24点游戏,用随机的四个数字算出24!如果发现无解,可回答“无解”。(一个一个回答,如:输入一,计算机回答收到,输入×,计算机回答收到,再输入一,计算机回答1×1=2)’)
print(‘数字是%s.’%(shuzi_str))
shuzi=int(input(‘请输入数字:’))
print(‘收到%d’%(shuzi))
fuhao=input(‘请输入运算符号:’)
print(‘收到%s’%(fuhao))
编到这里我就发现,变量shuzi和fuhao无法加起来,成为完整的算式并得出结果。并且,试运行时发现程序报错:
runfile(’/home/jiangyizheng/桌面/程序/24点.py’, wdir=’/home/jiangyizheng/桌面/程序’)
Traceback (most recent call last):

File “/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py”, line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File “”, line 1, in
runfile(’/home/jiangyizheng/桌面/程序/24点.py’, wdir=’/home/jiangyizheng/桌面/程序’)

File “/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py”, line 827, in runfile
execfile(filename, namespace)

File “/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py”, line 110, in execfile
exec(compile(f.read(), filename, ‘exec’), namespace)

File “/home/jiangyizheng/桌面/程序/24点.py”, line 8
global shuzi_str
^
SyntaxError: name ‘shuzi_str’ is assigned to before global declaration
求大佬帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值