鱼C论坛

 找回密码
 立即注册
查看: 3059|回复: 8

if无法进行判断

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

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

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

x

list_all=[]
z=[]
Input=input().strip()
while Input != '':
    list_all.append(list(Input.split()))
    Input=input().strip()
list_all=sum(list_all,[])
n=list_all[0]
t=list_all[1]
a=list_all[3]
b=list_all[3]
c=list_all[5]
if n==1:
    if a>t:
        print(t)
    else:
        print(a)
if n==2:
    if b>t:
        print(t)
    else:
        print(t-b+1)


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

使用道具 举报

 楼主| 发表于 2023-2-28 16:17:01 | 显示全部楼层
有无老哥来帮一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-2-28 16:18:09 | 显示全部楼层
  1. list_all=[]
  2. z=[]
  3. Input=input().strip()
  4. while Input != '':
  5.     list_all.append(list(Input.split()))
  6.     Input=input().strip()
  7. list_all=sum(list_all,[])
  8. n=int(list_all[0])                         # 要转成 int
  9. t=int(list_all[1])
  10. a=int(list_all[3])
  11. b=int(list_all[3])
  12. c=int(list_all[5])
  13. if n==1:
  14.     if a>t:
  15.         print(t)
  16.     else:
  17.         print(a)
  18. if n==2:
  19.     if b>t:
  20.         print(t)
  21.     else:
  22.         print(t-b+1)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2023-2-28 16:27:07 | 显示全部楼层

还想再问一下就是我在输入数值后要多按一次空格才行,这怎么解决呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-2-28 16:31:11 | 显示全部楼层
shuaity 发表于 2023-2-28 16:27
还想再问一下就是我在输入数值后要多按一次空格才行,这怎么解决呢


把 c 那一行(第十二行)删掉

修改后的代码:
  1. list_all=[]
  2. z=[]
  3. Input=input().strip()
  4. while Input != '':
  5.     list_all.append(list(Input.split()))
  6.     Input=input().strip()
  7. list_all=sum(list_all,[])
  8. n=int(list_all[0])                         # 要转成 int
  9. t=int(list_all[1])
  10. a=int(list_all[3])
  11. b=int(list_all[3])
  12. if n==1:
  13.     if a>t:
  14.         print(t)
  15.     else:
  16.         print(a)
  17. if n==2:
  18.     if b>t:
  19.         print(t)
  20.     else:
  21.         print(t-b+1)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2023-2-28 16:34:10 | 显示全部楼层
isdkz 发表于 2023-2-28 16:31
把 c 那一行(第十二行)删掉

修改后的代码:

C的那一行是用来判断更多的行数时候用的,后来我加入了一个if让它不会有影响了
list_all=[]
z=[]
Input=input().strip()
while Input != '':
    list_all.append(list(Input.split()))
    Input=input().strip()
list_all=sum(list_all,[])
n=int(list_all[0])                       
t=int(list_all[1])
a=int(list_all[3])
b=int(list_all[3])
if len(list_all)>4:
    c=int(list_all[5])
if n==1:
    if a>t:
        print(t)
    else:
        print(a)
if n==2:
    if b>t:
        print(t)
    else:
        print(b+1)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-2-28 16:34:59 | 显示全部楼层
isdkz 发表于 2023-2-28 16:31
把 c 那一行(第十二行)删掉

修改后的代码:

加入之后虽然没有影响了但是仍然有存在
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-2-28 16:36:42 | 显示全部楼层
shuaity 发表于 2023-2-28 16:34
加入之后虽然没有影响了但是仍然有存在


存在啥?就不明白了,你的 c 又没有用到,留着它干嘛
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 0 反对 1

使用道具 举报

发表于 2023-3-1 16:25:14 | 显示全部楼层
本帖最后由 chinajz 于 2023-3-1 16:44 编辑
  1. #coding:gbk
  2. list_all=[]
  3. z=[]
  4. #Input=input().strip()
  5. for i in range(6):
  6.     Input=input().strip()
  7.     list_all.append(list(Input.split()))
  8. list_all=sum(list_all,[])
  9. print(list_all)
  10. n=int(list_all[0])                         # 要转成 int
  11. t=int(list_all[1])
  12. a=int(list_all[3])
  13. b=int(list_all[3])
  14. c=int(list_all[5])

  15. if n==1:
  16.     if a>t:
  17.         print(t)
  18.     else:
  19.         print(a)
  20. if n==2:
  21.     if b>t:
  22.         print(t)
  23.     else:
  24.         print(t-b+1)
复制代码

运行:
  1. 1
  2. 3
  3. 4
  4. 5
  5. 6
  6. 4
  7. ['1', '3', '4', '5', '6', '4']
  8. 3
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-24 19:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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