按'o'时试图重复我的循环 [英] Trying to repeat my loop when I press 'o'

查看:54
本文介绍了按'o'时试图重复我的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 continuer =  True  
while continuer == True
dimension = int(输入(' 输入维度(entre 5 et 39):'))

如果维度< 5
dimension = int(输入(输入维度(entre 5 et 39 ):' ))
elif dimension> 39:
dimension = int(输入('
输入维度(entre 5 et 39 ):' ))
elif dimension%2 == 0:
dimension = int(输入('
输入维度(entre 5 et 39 ):' ))
else:
break

lettre =(input('
Choisir une lettre identifiant le motif voulu?:' ))

print(')
F:Fenêtre'
print('
L:Losange '
print('
C:Coin '
print('
X:Le X '
p rint(lettre)




choix = input('
Voulez-vous encore faire un choix de motif:[o / n] '
if choix =='
n '
print('
Fermeture du program。'
else:
continuer = True











我的无限循环怎么了?另外,当我要求输入新维度时,是否有更好的方法来改善我的循环,谢谢。



我尝试过的方法:



我已经有一段时间了,我无法找到重启循环的方法

解决方案

它看起来你想要嵌套循环:一个允许输入主题直到选择'n'的循环,以及允许输入尺寸和字母直到它们有效的嵌套循环。



类似于:

 continuer =  True  
while continuer == True
while True
dimension = int(输入(' 输入维度(entre 5 et 39):'))
if dimension> = 5 和维度< = 39 维度% 2 == 1
break

while True
lettre =(输入( ' Choisir une lettre identifiant le motif voulu?:'))
print ' F:Fenêtre'
< span class =code-keyword> print (' L:Losange'
print ' C:Coin'
print ' X: Le X'
如果 lettre == ' F' < span class =code-keyword>或 lettre == ' L' lettre == ' C' lettre == ' X'
break

choix = input(' Voulez-vous encore faire un choix de motif:[o / n]'
if choix == ' n'
print ' Fermeture du program。'
continuer = False


continuer = True
while continuer == True:
    dimension = int(input('enter a dimension (entre 5 et 39):'))

    if  dimension < 5:
        dimension = int(input(enter a dimension (entre 5 et 39):'))
    elif dimension > 39:
        dimension = int(input('enter a dimension (entre 5 et 39):'))
    elif dimension % 2 == 0:
        dimension = int(input('enter a dimension (entre 5 et 39):'))
    else:
        break

lettre = (input('Choisir une lettre identifiant le motif voulu?:'))

print('F : Fenêtre')
print('L : Losange')
print('C : Coin')
print('X : Le X')
print(lettre)




choix = input('Voulez-vous encore faire un choix de motif: [o/n]')
if choix == 'n':
    print('Fermeture du programme.')
else:
    continuer = True






Whats wrong with my infinite loop? Also, is there a better way to improve my loop when i ask to enter a new dimension, thanks.

What I have tried:

Ive been there for a while and i cant find a way to reboot my loop

解决方案

It looks like you want nested loops: one loop that allows entering a motif until 'n' is chosen, and nested loops that allow entering a dimension and letter until they're valid.

Something like:

continuer = True
while continuer == True:
	while True:
		dimension = int(input('enter a dimension (entre 5 et 39):'))
		if dimension >= 5 and dimension <= 39 and dimension % 2 == 1:
			break

	while True:
		lettre = (input('Choisir une lettre identifiant le motif voulu?:'))
		print('F : Fenêtre')
		print('L : Losange')
		print('C : Coin')
		print('X : Le X')
		if lettre == 'F' or lettre == 'L' or lettre == 'C' or lettre == 'X':
			break

	choix = input('Voulez-vous encore faire un choix de motif: [o/n]')
	if choix == 'n':
		print('Fermeture du programme.')
		continuer = False


这篇关于按'o'时试图重复我的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆