YMAX317 发表于 2022-2-23 23:54:52

请问一下为啥一直说我的代码缩进错误呀

本帖最后由 YMAX317 于 2022-2-24 00:24 编辑

这是代码(刚学还有好多东西不知道):
import random

secret = random.ranint (1,10)
   
temp = input ("哥哥猜一下我心里想的是哪个数字嘛?")

guess = int(temp)

times = 1
   

while (guess != secret) and (times < 3):
          
    if guess > secret:
       
      print ("哥哥大了嘛~")

    else:
               
      print ("哥哥小了嘛~")


    temp = input ("哥哥再试一下嘛~说不定就猜对了呢?")

    guess = int (temp)

    times = times + 1
      

if (times <= 3) and (guess == sexret):
          
    print ("哎呀~哥哥你真懂我~")
       
    print ("不过猜对了也没有奖励,略略略")
       
else:
          
    print ("哼,给了三次机会都没猜中,不跟你玩了!")

人造人 发表于 2022-2-23 23:58:20

学编程就请认真一点吧
secret = random.ranint (1,10)
AttributeError: module 'random' has no attribute 'ranint'. Did you mean: 'randint'?

isdkz 发表于 2022-2-23 23:58:24

没有缩进错误,就是有一些地方打错了
import random

secret = random.randint (1,10)          # randint 打错了
   
temp = input ("哥哥猜一下我心里想的是哪个数字嘛?")

guess = int(temp)

times = 1
   

while (guess != secret) and (times < 3):
            
    if guess > secret:
      
      print ("哥哥大了嘛~")

    else:
               
      print ("哥哥小了嘛~")


    temp = input ("哥哥再试一下嘛~说不定就猜对了呢?")

    guess = int (temp)

    times = times + 1
      

if (times <= 3) and (guess == secret):      # secret 打错了
            
    print ("哎呀~哥哥你真懂我~")
      
    print ("不过猜对了也没有奖励,略略略")
      
else:
            
    print ("哼,给了三次机会都没猜中,不跟你玩了!")

YMAX317 发表于 2022-2-24 00:22:06

咳咳,手冷

YMAX317 发表于 2022-2-24 00:22:54

人造人 发表于 2022-2-23 23:58
学编程就请认真一点吧

咳咳手冷

YMAX317 发表于 2022-2-24 00:23:33

isdkz 发表于 2022-2-23 23:58
没有缩进错误,就是有一些地方打错了

谢了谢了,天太冷了
页: [1]
查看完整版本: 请问一下为啥一直说我的代码缩进错误呀