鱼C论坛

 找回密码
 立即注册
查看: 2182|回复: 3

写的东西跑不起来,好像是缩进问题

[复制链接]
发表于 2020-9-23 13:25:30 | 显示全部楼层 |阅读模式

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

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

x
但是我认真把缩进都对齐了,还是会报错 ,求助

代码:
  1. import random
  2. from fractions import Fraction

  3. password = 'Y'

  4. while password == 'Y':
  5.     while True:
  6.         son = random.randint(1,30)
  7.         if son % 3 == 0:
  8.             continue
  9.         print(Fraction(son,3),end=' ')
  10.             break
  11.     while True:
  12.         son = random.randint(1,30)
  13.         if son % 4 == 0:
  14.             continue
  15.         print(Fraction(son,4)end=' ')
  16.             break
  17.     while True:
  18.         son = random.randint(1,30)
  19.         if son % 6 == 0:
  20.             continue
  21.         print(Fraction(son,6))
  22.             break
  23.     while True:
  24.         password = input('continue?(Y/N)')
  25.         if password != 'N' and password != 'Y':
  26.             print('please print Y or N!!')
  27.             continue

  28. print('end')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-9-23 13:32:56 | 显示全部楼层
你写的是想要实现怎么样?这里面,又有contine又有break?pirnt下面怎么又缩进了?
  1. while True:
  2.         son = random.randint(1,30)
  3.         if son % 3 == 0:
  4.             continue
  5.         print(Fraction(son,3),end=' ')
  6.             break
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-23 13:34:44 From FishC Mobile | 显示全部楼层
你的代码逻辑有问题,得不出结果,我只改了报错的地方
  1. # -*- coding: utf-8 -*-

  2. import random
  3. from fractions import Fraction

  4. password = 'Y'

  5. while password == 'Y':
  6.     while True:
  7.         son = random.randint(1,30)
  8.         if son % 3 == 0:
  9.             continue
  10.         print(Fraction(son,3),end=' ')
  11.         break    # 这里break应与print齐平,因为他们没有从属关系,以下同理
  12.     while True:
  13.         son = random.randint(1,30)
  14.         if son % 4 == 0:
  15.             continue
  16.         print(Fraction(son,4), end=' ') #这里end前面缺个逗号
  17.         break
  18.     while True:
  19.         son = random.randint(1,30)
  20.         if son % 6 == 0:
  21.             continue
  22.         print(Fraction(son,6))
  23.         break
  24.     while True:
  25.         password = input('continue?(Y/N)')
  26.         if password != 'N' and password != 'Y':
  27.             print('please print Y or N!!')
  28.             continue

  29. print('end')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-23 14:24:22 | 显示全部楼层
  1. import random
  2. from fractions import Fraction

  3. f = True
  4. while f :
  5.     while True:
  6.         son = random . randint(1 , 30)
  7.         if son % 3 :
  8.             print(Fraction(son , 3) , end = ' ')
  9.             break
  10.     while True:
  11.         son = random . randint(1 , 30)
  12.         if son % 4 :
  13.             print(Fraction(son , 4) , end = ' ')
  14.             break
  15.     while True:
  16.         son = random . randint(1 , 30)
  17.         if son % 6 :
  18.             print(Fraction(son , 6))
  19.             break
  20.     while True:
  21.         password = input('continue?(Y/N)') . strip()
  22.         if password :
  23.             if password in ('Y' , 'y' , 'N' , 'n') :
  24.                 if password not in ('Y' , 'y') :
  25.                     f = False
  26.                 break
  27.             else :
  28.                 print('please print Y or N!!')
  29.         else :
  30.             f = False
  31.             break
  32. print('end')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-27 13:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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