怎样解决这个错误
import easyguiimport random
secret=random.randint(1,10)
sore=3
print ('------------I love you !-----------')
def func1(guess):
if (guess==secret):
easygui.msgbox ('我操,居然猜对')
easygui.msgbox ('不过猜对也没有奖,哈哈')
else:
if(guess>secret):
easygui.msgbox ("哥,大了大了~~!")
else:
easygui.msgbox("嘿,小了小了~~!!")
def func2():
temp=easygui.enterbox('请录入你猜到的数字:')
while temp.isdigit()!=1:
temp=easygui.enterbox ('请输入整数数字:')
guess=int(temp)
func1(temp)
while sore>1:
func2()
sore-=1
easygui.msgbox('游戏结束!') 错误呢 隔壁繁星吖 发表于 2020-4-13 22:14
错误呢
Traceback (most recent call last):
File "E:/A/python/Exercise/easygui 4-13.py", line 26, in <module>
func2()
File "E:/A/python/Exercise/easygui 4-13.py", line 22, in func2
func1(temp)
File "E:/A/python/Exercise/easygui 4-13.py", line 12, in func1
if(guess>secret):
TypeError: '>' not supported between instances of 'str' and 'int' import easygui
import random
secret = random.randint(1, 10)
sore = 3
print('------------I love you !-----------')
def func1(guess):
if (guess == secret):
easygui.msgbox('我操,居然猜对')
easygui.msgbox('不过猜对也没有奖,哈哈')
else:
if (guess > secret):
easygui.msgbox("哥,大了大了~~!")
else:
easygui.msgbox("嘿,小了小了~~!!")
def func2():
temp = easygui.enterbox('请录入你猜到的数字:')
while temp.isdigit() != 1:
temp = easygui.enterbox('请输入整数数字:')
guess = int(temp)
func1(int(temp))
while sore > 1:
func2()
sore -= 1
easygui.msgbox('游戏结束!') 你这个问题很简单secret = random.randint(1, 10)中是一个int类型的 而你传给他的guess是一个字符串 str和int不能进行判断 类型都不一样
你原本是这样的func1(temp)这个传进去是一个字符串 我改成了func1(int(temp)) 就可以了 import easygui,os
import random
secret=random.randint(1,1)
sore=3
print ('------------I love you !-----------')
def func1(guess):
if (guess==secret):
easygui.msgbox ('我操,居然猜对')
easygui.msgbox ('不过猜对也没有奖,哈哈')
easygui.msgbox('游戏结束!')
os._exit(0)
else:
if(guess>secret):
easygui.msgbox ("哥,大了大了~~!")
else:
easygui.msgbox("嘿,小了小了~~!!")
def func2():
temp=easygui.enterbox('请录入你猜到的数字:')
while temp.isdigit()!=1:
temp=easygui.enterbox ('请输入整数数字:')
guess=int(temp)
func1(guess)
while sore>0:
func2()
sore-=1
easygui.msgbox('游戏结束!')
admintest166 发表于 2020-4-13 22:22
你这个问题很简单secret = random.randint(1, 10)中是一个int类型的 而你传给他的guess是一个字符串 st ...
谢谢,改为 func1(guess)就好了,忘了改变量
页:
[1]