python - 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
编辑:翻译
解决方案
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
推荐阅读
- clickhouse - 如何检查是否真的应用了 Clickhouse 服务器设置?
- excel - 如何在 csv 中将所有日期时间转换为一种标准格式 yyyy-mm-dd hh:mm:ss AM/PM?
- python - Docker:执行“RUN pip install --no-cache /wheels/*”命令时出错
- excel - 如何从 VBA 中的两个数组函数获取单个数组输出?
- java - r2dbc ReactiveCrudRepository 如何编写 JPQL/HQL
- python - Twitch discord.py 机器人
- javascript - 如何在 Mac 桌面上成功显示使用 HTML5 画布绘制的图像的对比度差异?
- android - android EditText 焦点行为
- python - 时间数据 '03/16/2021 5:06 PM' 与格式 '%d/%m/%Y %I:%M %p' 不匹配
- node.js - 当我尝试在 MongoDB 数据库中上传图像时,出现 multer 错误