找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2954|回复: 4

[求助] 刚刚接触编程,也刚刚接触python

1

主题

2

帖子

2

积分

贫民

积分
2
水滴 发表于 2018-10-25 18:24:54 | 显示全部楼层 |阅读模式
昨天按照《父与子的编程之旅》里面的实例编写,但是总是出错。

import random
secret = random.randint(1,99)
guess=0
tires=0
print "AHOY! i`m the dread print Roberts,and i have a secret!"
print "it`s a nunber form 1 to 99.i`ll give you 6 tries"
while guess != secret and tries < 6:
    guess =input("what`s yer guess?")
    if guess <secret:
        print "too low,ye scurvy dog!"
    elif guess > sceret:
            print "too high,landlubber!"

            tries=tries+1

if guess ==secret:
    print "avast!ye got it! found my secret,ye did!"
else:
    print "no more guesses!better luck next time,matey!"
    print "the secret numaber was",secret



F5之后
>>> ================================ RESTART ================================
>>>
AHOY! i`m the dread print Roberts,and i have a secret!
it`s a nunber form 1 to 99.i`ll give you 6 tries

Traceback (most recent call last):
  File "E:\My python\学习过程\猜数游戏.py", line 7, in <module>
    while guess != secret and tries < 6:
NameError: name 'tries' is not defined
>>>


回复

使用道具 举报

0

主题

956

帖子

956

积分

圣骑士

积分
956
sheeboard 发表于 2018-10-25 21:26:48 | 显示全部楼层
声明变量是tires,不是tries,打错字了
回复 支持 反对

使用道具 举报

1

主题

2

帖子

2

积分

贫民

积分
2
水滴  楼主| 发表于 2018-10-25 21:49:06 | 显示全部楼层
谢谢您为我解答这个疑问
回复 支持 反对

使用道具 举报

0

主题

1

帖子

1

积分

贫民

积分
1
billuck 发表于 2018-10-26 15:06:33 | 显示全部楼层
import random
secret = random.randint(1,99)
guess=0
tires=0
print ("AHOY! i`m the dread print Roberts,and i have a secret!")
print ("it`s a nunber form 1 to 99.i`ll give you 6 tries")
while guess != secret and tires < 6:
    guess =int(input("what`s yer guess?"))
    if guess <secret:
        print ("too low,ye scurvy dog!")
    elif guess > secret:
        print ("too high,landlubber!")

    tires=tires+1

if guess ==secret:
    print( "avast!ye got it! found my secret,ye did!")
else:
    print ("no more guesses!better luck next time,matey!")
    print ("the secret numaber was %d" % secret)
回复 支持 反对

使用道具 举报

17

主题

85

帖子

85

积分

新手

积分
85
我是吃货 发表于 2018-11-13 19:53:18 | 显示全部楼层
本帖最后由 我是吃货 于 2018-11-13 19:59 编辑

有心看这本书,算是想得多。
诶诶,父与子吗???
下面蠢猪是瞎写的……………………………………………………………………………………………………………………
  1. <div>import sys</div><div>def fuyuzi():</div><div>    print('欢迎您来到父与子的时间世界!')</div>
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表