鱼C论坛

 找回密码
 立即注册
查看: 2524|回复: 11

[已解决]各位高手请进来解答

[复制链接]
发表于 2020-2-28 16:09:32 | 显示全部楼层 |阅读模式

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

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

x
print("Hello,welcome to play this game")
name = input("Now,please tell me you name:")
print("Welcome back"+ name +"!")
print("Now,i want to ask you some question")
num = input("The first question is 9+8=:")
if num == 17:
    print("Good,It's right")
else:
    print("No,It's wrong")
num2 = input("Now,the second question is 9-2=:")
if num2 == 7:
    print("Good,It's right")
else:
    print("No,It's wrong")
num3 =input("Now,the third question is 6*6")
if num3 == 36:
    print("Good,It's right")
else:
    print("No,It's wrong")
num4 = input("The last questian is 6/3")
if num4 == 2:
    print("Good,It's right")
else:
    print("No,It's wrong")
print("Thanks for your play")
print("I wish you will like whis game ")
print("I hope you can come to play the game made by me again")
print("Bye bye")
上面这串代码运行后就是输入的是正确答案回答也是wrong,请问哪里有问题,该怎么修改?
(初学者,看过第三集小甲鱼的Python视频后就想着自己也做一个,还有很多东西我都不懂,也请各位大神多包涵)

最佳答案
2020-2-28 16:14:48
input的默认返回值是字符串,要将字符串转换成int类型
  1. print("Hello,welcome to play this game")
  2. name = input("Now,please tell me you name:")
  3. print("Welcome back"+ name +"!")
  4. print("Now,i want to ask you some question")
  5. num = int(input("The first question is 9+8=:"))
  6. if num == 17:
  7.     print("Good,It's right")
  8. else:
  9.     print("No,It's wrong")
  10. num2 = input("Now,the second question is 9-2=:")
  11. if num2 == 7:
  12.     print("Good,It's right")
  13. else:
  14.     print("No,It's wrong")
  15. num3 =input("Now,the third question is 6*6")
  16. if num3 == 36:
  17.     print("Good,It's right")
  18. else:
  19.     print("No,It's wrong")
  20. num4 = input("The last questian is 6/3")
  21. if num4 == 2:
  22.     print("Good,It's right")
  23. else:
  24.     print("No,It's wrong")
  25. print("Thanks for your play")
  26. print("I wish you will like whis game ")
  27. print("I hope you can come to play the game made by me again")
  28. print("Bye bye")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-28 16:12:34 | 显示全部楼层
num、num2、num3、num4 都是字符串,要使用 int() 方法转化成整数。

代码帮你改好了:

  1. print("Hello,welcome to play this game")
  2. name = input("Now,please tell me you name:")
  3. print("Welcome back" + name + "!")
  4. print("Now,i want to ask you some question")
  5. num = int(input("The first question is 9+8=:"))
  6. if num == 17:
  7.     print("Good,It's right")
  8. else:
  9.     print("No,It's wrong")
  10. num2 = int(input("Now,the second question is 9-2=:"))
  11. if num2 == 7:
  12.     print("Good,It's right")
  13. else:
  14.     print("No,It's wrong")
  15. num3 = int(input("Now,the third question is 6*6"))
  16. if num3 == 36:
  17.     print("Good,It's right")
  18. else:
  19.     print("No,It's wrong")
  20. num4 = int(input("The last questian is 6/3"))
  21. if num4 == 2:
  22.     print("Good,It's right")
  23. else:
  24.     print("No,It's wrong")
  25. print("Thanks for your play")
  26. print("I wish you will like whis game ")
  27. print("I hope you can come to play the game made by me again")
  28. print("Bye bye")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 16:14:48 | 显示全部楼层    本楼为最佳答案   
input的默认返回值是字符串,要将字符串转换成int类型
  1. print("Hello,welcome to play this game")
  2. name = input("Now,please tell me you name:")
  3. print("Welcome back"+ name +"!")
  4. print("Now,i want to ask you some question")
  5. num = int(input("The first question is 9+8=:"))
  6. if num == 17:
  7.     print("Good,It's right")
  8. else:
  9.     print("No,It's wrong")
  10. num2 = input("Now,the second question is 9-2=:")
  11. if num2 == 7:
  12.     print("Good,It's right")
  13. else:
  14.     print("No,It's wrong")
  15. num3 =input("Now,the third question is 6*6")
  16. if num3 == 36:
  17.     print("Good,It's right")
  18. else:
  19.     print("No,It's wrong")
  20. num4 = input("The last questian is 6/3")
  21. if num4 == 2:
  22.     print("Good,It's right")
  23. else:
  24.     print("No,It's wrong")
  25. print("Thanks for your play")
  26. print("I wish you will like whis game ")
  27. print("I hope you can come to play the game made by me again")
  28. print("Bye bye")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-28 16:16:07 | 显示全部楼层
qiuyouzhi 发表于 2020-2-28 16:14
input的默认返回值是字符串,要将字符串转换成int类型

哦谢谢啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 16:16:23 | 显示全部楼层

如果有帮助,请设最佳答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 16:16:38 | 显示全部楼层
帮你改好了,问题在注释里:
  1. print("Hello,welcome to play this game")
  2. name = input("Now,please tell me you name:")
  3. print("Welcome back "+ name +"!")
  4. print("Now,i want to ask you some question")

  5. #和整数数字比较记得加上 int() ,因为input()返回的是一个字符串,它跟整数比较,当然是返回False
  6. num = int(input("The first question is 9+8=:"))
  7. if num == 17:
  8.     print("Good,It's right")
  9. else:
  10.     print("No,It's wrong")

  11. num2 = int(input("Now,the second question is 9-2=:")) #问题同上,改好了
  12. if num2 == 7:
  13.     print("Good,It's right")
  14. else:
  15.     print("No,It's wrong")

  16. num3 = int(input("Now,the third question is 6*6:")) #问题同上
  17. if num3 == 36:
  18.     print("Good,It's right")
  19. else:
  20.     print("No,It's wrong")

  21. num4 = int(input("The last questian is 6/3:")) #问题同上
  22. if num4 == 2:
  23.     print("Good,It's right")
  24. else:
  25.     print("No,It's wrong")

  26. print("Thanks for your play")
  27. print("I wish you will like whis game ")
  28. print("I hope you can come to play the game made by me again")
  29. print("Bye bye")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-28 16:16:38 | 显示全部楼层
qiuyouzhi 发表于 2020-2-28 16:14
input的默认返回值是字符串,要将字符串转换成int类型

谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 16:17:09 | 显示全部楼层

如果有帮助请设最佳答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-28 16:18:37 | 显示全部楼层
yexing 发表于 2020-2-28 16:16
帮你改好了,问题在注释里:

谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-28 17:39:23 | 显示全部楼层
qiuyouzhi 发表于 2020-2-28 16:16
如果有帮助,请设最佳答案

已经是了啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-28 17:40:39 | 显示全部楼层

抱歉,那时候卡了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-28 18:20:24 | 显示全部楼层
qiuyouzhi 发表于 2020-2-28 17:40
抱歉,那时候卡了

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-1 20:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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