王冯蕊 发表于 6 天前

已经坚持四天了,会一些简单代码

timu_one = input("3 + 5 = ?")
timu_two = input("10 % 3 = ?")
timu_three = input("5 > 3 的结果是 True 还是 False?")
timu_one = int(timu_one)
timu_two = int(timu_two)
if timu_two == 8:
    print("正确")
    else:
      print("错误")
if timu_two == 1:
    print("正确")
    else:
      print("错误")
if timu_three == "True":
    print("正确")
    else:
      print("错误")
if timu_one == 8 and timu_two == 1 and timu_three == "True":
    print("3/3")
else:
    print("不及格")


怎么样,我是不是很棒!网上说小甲鱼的作业不适合新手,我就要求Ai给我布置作业,效果意外地不错。

FishC 发表于 6 天前

很棒!坚持四天了,继续加油!你的代码思路不错,但有几个小错误需要修正。主要问题在于缩进和逻辑判断。

首先,Python对缩进非常严格,else必须与对应的if对齐。其次,第一个判断应该是检查timu_one(3+5的结果),而不是timu_two。

这是修正后的代码:

timu_one = input("3 + 5 = ?")
timu_two = input("10 % 3 = ?")
timu_three = input("5 > 3 的结果是 True 还是 False?")
timu_one = int(timu_one)
timu_two = int(timu_two)

if timu_one == 8:
    print("正确")
else:
    print("错误")

if timu_two == 1:
    print("正确")
else:
    print("错误")

if timu_three == "True":
    print("正确")
else:
    print("错误")

if timu_one == 8 and timu_two == 1 and timu_three == "True":
    print("3/3")
else:
    print("不及格")


关键点解释:
1. 缩进:确保else与if在同一列开始。
2. 逻辑:第一个问题对应timu_one,第二个对应timu_two。
3. 字符串比较:timu_three是字符串,所以比较时需完全匹配"True",用户输入必须是大写开头。如果需要更灵活,可以改用timu_three.lower() == "true"来忽略大小写。

你正在进步,多练习会越来越熟练!如果还有问题,随时来问。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

空python 发表于 5 天前

学习了
页: [1]
查看完整版本: 已经坚持四天了,会一些简单代码