鱼C论坛

 找回密码
 立即注册
查看: 2057|回复: 1

[已解决]求助大佬,如何实现这个功能

[复制链接]
发表于 2021-7-16 12:58:45 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 桐生战兔丶 于 2021-7-16 13:04 编辑

想让这个程序能够反复使用而不是完成以后需要重新启动一次,所以我写了如图一的代码,但是我用的方法并不能实现如图二。求助大佬指点迷津
附上代码:
print('.....................................................')
h=input('enter your point >> ')
i=1
d=1
while d!=100:
    while i!= 2:
        if not h.isdigit():
            print('your key words is not number')
            h=input('enter your point >> ')
        else :
           i=i+1
    y=int(h)      
    while i!= 3:
        if y>100 or y<1:
            print(' the number is entered by your entering must be between 1 and 100')
            h=input('enter your point >> ')
        else :
            i=i+1
    y=int(h)
    if y > 60 and y < 80:
        print (h+' got C')
        d=d+1
    elif y < 60:
        print (h+' got D')
        d=d+1
    else :
        print (h+' got A')
        d=d+1
最佳答案
2021-7-16 13:18:39
本帖最后由 青出于蓝 于 2021-7-16 13:20 编辑
  1. while True:
  2.     print('.....................................................')
  3.     h=input('enter your point >> ')
  4.     i=1
  5.     d=1
  6.     while d!=2:
  7.         while i!= 2:
  8.             if not h.isdigit():
  9.                 print('your key words is not number')
  10.                 h=input('enter your point >> ')
  11.             else :
  12.                i=i+1
  13.         y=int(h)      
  14.         while i!= 3:
  15.             if y>100 or y<1:
  16.                 print(' the number is entered by your entering must be between 1 and 100')
  17.                 h=input('enter your point >> ')
  18.             else :
  19.                 i=i+1
  20.         y=int(h)
  21.         if y >= 60 and y < 80:
  22.             print (h+' got C')
  23.             d=d+1
  24.         elif y < 60:
  25.             print (h+' got D')
  26.             d=d+1
  27.         else :
  28.             print (h+' got A')
  29.             d=d+1
复制代码

1,这个d!=100不需要,可以在外面套一个大循环实现
2,源代码有一点错误,判断时输入61为C,但输入60为A。判断代码写错了,已经改了
q3(2).png
q3.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-7-16 13:18:39 | 显示全部楼层    本楼为最佳答案   
本帖最后由 青出于蓝 于 2021-7-16 13:20 编辑
  1. while True:
  2.     print('.....................................................')
  3.     h=input('enter your point >> ')
  4.     i=1
  5.     d=1
  6.     while d!=2:
  7.         while i!= 2:
  8.             if not h.isdigit():
  9.                 print('your key words is not number')
  10.                 h=input('enter your point >> ')
  11.             else :
  12.                i=i+1
  13.         y=int(h)      
  14.         while i!= 3:
  15.             if y>100 or y<1:
  16.                 print(' the number is entered by your entering must be between 1 and 100')
  17.                 h=input('enter your point >> ')
  18.             else :
  19.                 i=i+1
  20.         y=int(h)
  21.         if y >= 60 and y < 80:
  22.             print (h+' got C')
  23.             d=d+1
  24.         elif y < 60:
  25.             print (h+' got D')
  26.             d=d+1
  27.         else :
  28.             print (h+' got A')
  29.             d=d+1
复制代码

1,这个d!=100不需要,可以在外面套一个大循环实现
2,源代码有一点错误,判断时输入61为C,但输入60为A。判断代码写错了,已经改了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-21 16:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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