How do I transform this into REPEAT-UNTIL loop or FOR loop? Or maybe there's another way to make both a triangle and a trapezoid in one program? The program requires details as if the program's talking to people. Thank you very much. I'd really appreciate your help.
def triangle(n, m):
if n == m:
print(("*"*n).center(20))
else:
triangle(n-2,m)
print(("*"*n).center(20))
print("Type 1 to make a triangle and type 2 to make a trapezoid")
while True:
while True:
figure = int(input("Input the code of the desired figure: "))
if figure !=1 and figure != 2:
print("input does not fit")
else:
break
if figure == 1:
while True:
n = int(input("Input the number of pattern desired (must be odd number):"))
if n % 2 == 0:
print("Must be odd number!")
else:
break
m = 1
elif figure == 2:
while True:
n = int(input("Input the number of pattern desired (must be odd number > 3):"))
if n % 2 != 0 and n > 3:
break
else:
print("The number must be odd and greater than 3!")
while True:
m = int(input("Input an odd number less than " + str(n) + " and greater than 1 : "))
if 1 < m and m < n and m % 2 != 0:
break
else:
print("The odd number must be less than " + str(n) + " and greater than 1")
triangle(n,m)
while True:
tryagain = input("Do you want to try again? (y/n): ")
if tryagain != "y" and tryagain != "n":
print("input does not fit")
else:
break
if tryagain == "n":
break
Aucun commentaire:
Enregistrer un commentaire