用户:
嗯哼君 渠源查看:3 回复:16 评论:3 创建时间:2018-08-29T13:29:30
代码如下(及照片):(缩进被技术喵吃了)
import random
n = 0
def majorone():
print('first,you must calculate the result.')
asknumber(100,1)
def ask():
if (input() == 'yes') :
print('so come on!')
majorone()
elif (input('so can you beat me?') == 'no') :
print('bye bye!')
ask()
else :
print('please tell no or yes')
ask()
def majortwo():
asknumber(10000,1)
def majorthree():
print('well,you win!')
def asknumber(xx,yy):
x = random.randint(xx, yy)
y = random.randint(xx, yy)
if (input(x+'and'+y+'is?') != x+y) :
print('you fail.')
else :
print('next.')
if (n == 0) :
n = 1
majortwo()
else :
majorthree()
input('What`s your name?')
print('Welcome to my first works.')
ask()
运行之后系这样纸滴:
What`s your name?you guess
Welcome to my first works.
yes
so come on!
first,you must calculate the result.
Traceback (most recent call last):
File "C:\Users\ADMINI~1\AppData\Local\Temp\codemao-vWgNNf/temp.py", line 40, in <module>
ask()
File "C:\Users\ADMINI~1\AppData\Local\Temp\codemao-vWgNNf/temp.py", line 11, in ask
majorone()
File "C:\Users\ADMINI~1\AppData\Local\Temp\codemao-vWgNNf/temp.py", line 6, in majorone
asknumber(100,1)
File "C:\Users\ADMINI~1\AppData\Local\Temp\codemao-vWgNNf/temp.py", line 26, in asknumber
x = random.randint(xx, yy)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\random.py", line 220, in randint
return self.randrange(a, b+1)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\random.py", line 198, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (100,2, -98)
程序运行结束
各位dalao怎么办啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊我昨天才开始第一次接触Python
有两处错误:
1. 程序第28行错了 等式左边是字符串,等式右边是数字 你不能拿字符串和数字做比较
2. 第6行、20行,都属于执行尚未定义的函数,需要调整顺序哈
最后,欢迎向我提任何海龟编辑器的改进建议!!!!么么哒!!!!
点赞0
评论
嗯哼君 渠源但是第二次问题的时候又错误了,这次显示的是:
Traceback (most recent call last):
File "C:\Users\ADMINI~1\AppData\Local\Temp\codemao-fo0lHx/temp.py", line 26, in <module>
if (input(x+'and'+y+'is?') != int(x+y)) :
TypeError: unsupported operand type(s) for +: 'int' and 'str'
点赞0
评论
完整专家整理代码为:
import random
n = 0
def ask():
if (input() == 'yes') :
print('so come on!')
ask()
elif (input('so can you beat me?') == 'no') :
print('bye bye!')
ask()
else :
print('please tell no or yes')
ask()
input('What`s your name?')
print('Welcome to my first works.')
ask()
print('first,you must calculate the result.')
x = random.randint(1, 100)
y = random.randint(1, 100)
if (input(x+'and'+y+'is?') != int(x+y)) :
print('you fail.')
else :
print('next.')
x = random.randint(1, 10000)
y = random.randint(1, 10000)
if (input(x+'and'+y+'is?') != int(x+y)) :
print('you fail.')
else :
print('well,you win!')点赞1
评论