首页 > 解决方案 > Python 毕达哥拉斯

问题描述

如果您不输入数字,我正在尝试运行程序,但我不明白。任何人都可以帮忙吗?

loop=True
print("Velcome to the pythagorean triples generator, if you want the machine to stop type stop")
print("Choose an uneven number over 1")
while loop:
    number1 = input("write here: ")
    
    try:
        number = int(number1)
    except:
        print("It has to be a whole number")
        
    if int(number)%2 == 0 or int(number)==1 
        print("the number has to be uneven and bigger than 1")
    
    else:
        calculation = int(number) ** 2
        calculation2 = int(calculation) - 1
        calculation3 = int(calculation2) / 2
        print ("Here is your first number,", int(calculation3))
        calculation4 = int(calculation3) + 1
        print ("Here is your second number,", int(calculation4))
    
    if str(tal) == "stop":
        break

编辑:翻译

标签: pythonpythagorean

解决方案


loop = True
print("Velkommen til pythagoras tripler generatoren, hvis du vil stoppe maskinen skal du bare skrive stop")
print("Vælg et ulige tal over 1")
while loop:
    tal = input("Skiv her: ")

    try:
        number = int(tal)
    except Exception as e:
        print("Det skal være et tal")
        raise e // You should raise a Exception to let this program stops here.

    if int(number) % 2 == 0 or int(number) == 1: // You lack one ':'
        print("tallet skal være ulige og større end 1")

    else:
        udregning = int(number) ** 2
        udregning2 = int(udregning) - 1
        udregning3 = int(udregning2) / 2
        print("Her er dit ene tal,", int(udregning3))
        udregning4 = int(udregning3) + 1
        print("Her er dit andet tal,", int(udregning4))

    if str(tal) == "stop":
        break

推荐阅读