鱼C论坛

 找回密码
 立即注册
查看: 3284|回复: 2

[萌新报道] 求助

[复制链接]
发表于 2022-9-10 14:19:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
哪里有问题
  1. import random
  2. no = random.randint(1,4)
  3. name = input("请输入您的姓名:")
  4. print('你好,' + name + '!''开始答题')
  5. temp = input("1+1:")
  6. guess = int(temp)
  7. while guess != 2:
  8.     if guess < 2:
  9.             print('小了')
  10.     if guess > 2:
  11.             print("大了")
  12.     temp = input("新的填入:")
  13.     guess = int(temp)
  14. print("通知:正确")

  15. temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:")
  16. yet = int(temp)
  17. if yet != no:
  18.     print('错了!答案:' + no + '!')
  19. else:
  20.     print('对了!答案:'+ no + '!')
  21. print()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-9-10 14:50:01 | 显示全部楼层
本帖最后由 hveagle 于 2022-9-10 14:56 编辑

1 Your Demo 你的代码
  1. import random
  2. no = random.randint(1,4)
  3. name = input("请输入您的姓名:")
  4. print('你好,' + name + '!''开始答题')
  5. temp = input("1+1:")
  6. guess = int(temp)
  7. while guess != 2:
  8.     if guess < 2:
  9.             print('小了')
  10.     if guess > 2:
  11.             print("大了")
  12.     temp = input("新的填入:")
  13.     guess = int(temp)
  14. print("通知:正确")

  15. temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:")
  16. yet = int(temp)
  17. if yet != no:
  18.     print('错了!答案:' + no + '!')
  19. else:
  20.     print('对了!答案:'+ no + '!')
  21. print()
复制代码

2 My Demo 我的代码
  1. import random
  2. no = random.randint(1,4)
  3. name = input("请输入您的姓名:")
  4. print('你好,' + name + '!''开始答题')
  5. temp = input("1+1:")
  6. guess = int(temp)
  7. while guess != 2:
  8.     if guess < 2:
  9.             print('小了')
  10.     if guess > 2:
  11.             print("大了")
  12.     temp = input("新的填入:")
  13.     guess = int(temp)
  14. print("通知:正确")

  15. temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:")
  16. yet = int(temp)
  17. if yet != no:
  18.     print('错了!答案:' + str(no) + '!')
  19. else:
  20.     print('对了!答案:'+ str(no) + '!')
  21. print()
复制代码

3 Demo difference 代码差别(由于要批注,所以不用代码样式,红色代表要补上的部分,绿色代表要删掉的部分)
import random
no = random.randint(1,4)
name = input("请输入您的姓名:")
print('你好,' + name + '!''开始答题')
temp = input("1+1:")
guess = int(temp)
while guess != 2:
    if guess < 2:
            print('小了')
    if guess > 2:
            print("大了")
    temp = input("新的填入:")
    guess = int(temp)
print("通知:正确")

temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:")
yet = int(temp)
if yet != no:
    print('错了!答案:' + str(no) + '!')
else:
    print('对了!答案:'+ str(no) + '!')
print()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-10 15:46:09 | 显示全部楼层
no 是 int 类型 , 在与字符串拼接时 , 需要先转换为 str 形
当然 , 也可以这样写 :
  1. print('对了! 答案: ', no, '!', sep='')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-23 11:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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