写的东西跑不起来,好像是缩进问题
但是我认真把缩进都对齐了,还是会报错 ,求助代码:
import random
from fractions import Fraction
password = 'Y'
while password == 'Y':
while True:
son = random.randint(1,30)
if son % 3 == 0:
continue
print(Fraction(son,3),end=' ')
break
while True:
son = random.randint(1,30)
if son % 4 == 0:
continue
print(Fraction(son,4)end=' ')
break
while True:
son = random.randint(1,30)
if son % 6 == 0:
continue
print(Fraction(son,6))
break
while True:
password = input('continue?(Y/N)')
if password != 'N' and password != 'Y':
print('please print Y or N!!')
continue
print('end')
你写的是想要实现怎么样?这里面,又有contine又有break?pirnt下面怎么又缩进了?
while True:
son = random.randint(1,30)
if son % 3 == 0:
continue
print(Fraction(son,3),end=' ')
break 你的代码逻辑有问题,得不出结果,我只改了报错的地方
# -*- coding: utf-8 -*-
import random
from fractions import Fraction
password = 'Y'
while password == 'Y':
while True:
son = random.randint(1,30)
if son % 3 == 0:
continue
print(Fraction(son,3),end=' ')
break # 这里break应与print齐平,因为他们没有从属关系,以下同理
while True:
son = random.randint(1,30)
if son % 4 == 0:
continue
print(Fraction(son,4), end=' ') #这里end前面缺个逗号
break
while True:
son = random.randint(1,30)
if son % 6 == 0:
continue
print(Fraction(son,6))
break
while True:
password = input('continue?(Y/N)')
if password != 'N' and password != 'Y':
print('please print Y or N!!')
continue
print('end') import random
from fractions import Fraction
f = True
while f :
while True:
son = random . randint(1 , 30)
if son % 3 :
print(Fraction(son , 3) , end = ' ')
break
while True:
son = random . randint(1 , 30)
if son % 4 :
print(Fraction(son , 4) , end = ' ')
break
while True:
son = random . randint(1 , 30)
if son % 6 :
print(Fraction(son , 6))
break
while True:
password = input('continue?(Y/N)') . strip()
if password :
if password in ('Y' , 'y' , 'N' , 'n') :
if password not in ('Y' , 'y') :
f = False
break
else :
print('please print Y or N!!')
else :
f = False
break
print('end')
页:
[1]