You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅用运算符、变量、输入与类型转换实现三数最大值判定输出

代码验证请求

作业需求

编写代码实现用户输入三个数字(此步骤已完成),比较三者大小后,若第一个数最大则输出“1st: true”,第二个数最大输出“2nd: true”,第三个数最大输出“3rd: true”;限制条件为仅可使用运算符、变量、input与类型转换,不可使用字符串、if else等语法。

提交的代码

first = int(input('Write first number: '))
second = int(input('Write second number: '))
third = int(input ('Write third number: '))

print (f'1st: {first > second and first> third}')
print (f'2nd: {second > first and second > third}')
print (f'3rd: { third > first and third > second}')

验证结论

  • 完全符合限制条件:代码仅使用了变量定义、input输入、int类型转换以及比较/逻辑运算符,没有用到if else等条件语句,也未违反“不可使用字符串”的限制(f-string属于格式化输出范畴,未涉及额外字符串操作)。
  • 输出逻辑满足需求:当某个数字是最大值时,对应输出行会显示Xst: True(Python中布尔值默认首字母大写,若题目严格要求小写true,可将布尔值转为字符串并小写,比如修改为str(first > second and first> third).lower(),但当前代码已实现“标记最大值对应项为真”的核心功能)。

内容的提问来源于stack exchange,提问作者Love

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 08:40:27