鱼C论坛

 找回密码
 立即注册
查看: 1210|回复: 7

[已解决]新手求助!程序可以运营,但是运行不畅!

[复制链接]
发表于 2020-1-8 17:16:35 From FishC Mobile | 显示全部楼层 |阅读模式

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

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

x
2020年1月python新手!中年油腻大叔!笨蠢慢。
听了老师关于输入分数输出等级的课。我就像自由发挥一下,结果我的程序运行不畅啊!特请高手指点指点!

# 输入finish,退出程序!
# 输入除finish以外的字母或者数字字母,再次输入!
# 分数 < 0,分数 > 100,警告,再次输入!
# 0 <= 分数 < 60,D
# 60 <= 分数 < 80,C
# 80 <= 分数 < 90,B
# 90 <= 分数 < 100,A
# 分数 == 100,S

temp = input('分数:')
a = temp.isalpha()
if a != True:
    while temp != 'finish':
        score = int(temp)
        if 100 < score or score < 0:
            print('滚出去!叫家长!')
        elif score == 100:
            print('S')
        elif 90 <= score < 100:
            print('A')
        elif 80 <= score < 90:
            print('B')
        elif 60 <= score < 80:
            print('C')
        elif 0 < score < 60:
            print('D')
        temp = int(input('分数:'))
else:
    temp = input('分数:')
最佳答案
2020-1-9 17:51:17
big501 发表于 2020-1-8 21:24
另外,大神你改写的好像也有问题!正确分数输入1次后,就会退出来!

这样可以:

  1. temp = input('分数:')
  2. while temp != "finish":
  3.     while (not temp.isdigit()) or not (0 <= int(temp) <= 100):
  4.         if not temp.isdigit():
  5.             print("输入错误,请再次输入!")
  6.         elif not (0 <= int(temp) <= 100):
  7.             print("滚出去!叫家长!")
  8.         temp = input("分数:")
  9.     score = int(temp)
  10.     if score == 100:
  11.         print('S')
  12.     elif 90 <= score < 100:
  13.         print('A')
  14.     elif 80 <= score < 90:
  15.         print('B')
  16.     elif 60 <= score < 80:
  17.         print('C')
  18.     elif 0 <= score < 60:
  19.         print('D')
  20.     temp = input("分数:")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-1-8 17:37:48 | 显示全部楼层
本帖最后由 jackz007 于 2020-1-8 18:03 编辑
  1. f = True
  2. while f:
  3.     while f:
  4.         temp = input('分数:')
  5.         if temp . lower() == 'finish':
  6.             f = False
  7.             break
  8.         elif temp . isdigit():
  9.             score = int(temp)
  10.             if 0 <= score <= 100:
  11.                 if score == 100:
  12.                     print('S')
  13.                 elif 90 <= score < 100:
  14.                     print('A')
  15.                 elif 80 <= score < 90:
  16.                     print('B')
  17.                 elif 60 <= score < 80:
  18.                     print('C')
  19.                 elif 0 <= score < 60:
  20.                     print('D')
  21.                 break   
  22.             else:
  23.                 print('滚出去!叫家长!')
  24.         else:
  25.             print('请输入数字!')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-8 17:45:22 | 显示全部楼层
什么叫 “程序可以运营”?什么叫 “运行不畅”?拜托用词准确点。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-8 17:51:30 | 显示全部楼层
代码帮楼主改好了:

  1. temp = input('分数:')
  2. if temp != "finish":
  3.     while (not temp.isdigit()) or not (0 <= int(temp) <= 100):
  4.         if not temp.isdigit():
  5.             print("输入错误,请再次输入!")
  6.         elif not (0 <= int(temp) <= 100):
  7.             print("滚出去!叫家长!")
  8.         temp = input("分数:")
  9.     score = int(temp)
  10.     if score == 100:
  11.         print('S')
  12.     elif 90 <= score < 100:
  13.         print('A')
  14.     elif 80 <= score < 90:
  15.         print('B')
  16.     elif 60 <= score < 80:
  17.         print('C')
  18.     elif 0 <= score < 60:
  19.         print('D')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-8 21:19:45 | 显示全部楼层
zltzlt 发表于 2020-1-8 17:51
代码帮楼主改好了:

大神,牛逼啊!!我真的不知道我写的哪里有问题!为啥连续输入两次字母,就会退出程序呢!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-8 21:24:13 | 显示全部楼层
zltzlt 发表于 2020-1-8 17:51
代码帮楼主改好了:

另外,大神你改写的好像也有问题!正确分数输入1次后,就会退出来!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-9 17:51:17 | 显示全部楼层    本楼为最佳答案   
big501 发表于 2020-1-8 21:24
另外,大神你改写的好像也有问题!正确分数输入1次后,就会退出来!

这样可以:

  1. temp = input('分数:')
  2. while temp != "finish":
  3.     while (not temp.isdigit()) or not (0 <= int(temp) <= 100):
  4.         if not temp.isdigit():
  5.             print("输入错误,请再次输入!")
  6.         elif not (0 <= int(temp) <= 100):
  7.             print("滚出去!叫家长!")
  8.         temp = input("分数:")
  9.     score = int(temp)
  10.     if score == 100:
  11.         print('S')
  12.     elif 90 <= score < 100:
  13.         print('A')
  14.     elif 80 <= score < 90:
  15.         print('B')
  16.     elif 60 <= score < 80:
  17.         print('C')
  18.     elif 0 <= score < 60:
  19.         print('D')
  20.     temp = input("分数:")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-10 10:49:38 | 显示全部楼层

谢谢!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-26 17:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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