我一直在尝试更深入地编程,所以我一直在尝试制作一个简单的程序,它以两个数字作为输入,并计算最小公倍数。我在 Python 中这样做是因为我不知道如何在 Java 中接受输入。现在发生的事情是程序在我输入数字后挂起,什么也没有发生。这里的任何指针将不胜感激。谢谢你。
#LCM Calculator
#Author: Ethan Houston
#Language: Python
#Date: 2013-12-27
#Function: Program takes 2 numbers as input, and finds the lowest number
# that goes into each of them
def lcmCalculator(one, two):
""" takes two numbers as input, computes a number that evenly
divides both numbers """
counter = 2 #this is the number that the program tried to divide each number by.
#it increases by 1 if it doesn't divide evenly with both numbers.
while True:
if one % counter == 0 and two % counter == 0:
print counter
break
else:
counter += 1
print "\nThis program takes two numbers and computes the LCM of them...\n"
first_number = input("Enter your first number: ")
second_number = input("Enter your second number: ")
print lcmCalculator(first_number, second_number)