Python程序设计基础(第3版)——习题及答案 【ch03】Python程序的基本流程控制.docx

Python程序设计基础(第3版)——习题及答案 【ch03】Python程序的基本流程控制.docx

第三章Python程序的基本流程控制 1.编写程序,从键盘输入两点的坐标(xl,y1)和(x2,y2),计算并输出两点之间的距离。 答案: import math def calculate_distance(x1, y1, x2, y2): distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) return distance def main(): try: x1 = float(input(Enter the x-coordinate of the first point (x1): )) y1 = float(input(Enter the y-coordinate of the first point (y1): )) x2 = float(input(Enter the x-coordinate of the second point (x2): )) y2 = float(input(Enter the y-coordinate of the second point (y2): )) distance = calculate_distance(x1, y1, x2, y2) print(

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档