hr = int(input("Enter period of earth rotation : "))

ln = float(input("Enter value of longitude : "))

calc = (hr/360)*ln

print (calc)

输入: - 24,82.50

我希望输出为5:30,而不是5.5

分析解答

试试这个:

hr = int(input("Enter period of earth rotation : "))

ln = float(input("Enter value of longitude : "))

calc = (hr/360)*ln
hours = int(calc)
minutes = (calc*60) % 60

print("%d:%02d" % (hours, minutes))

产量

Enter period of earth rotation : 24
Enter value of longitude : 82.50
5:30