题目描述
无文字描述,看实例写代码
Test 1
Input | Output |
---|---|
4 6 | 2/3 |
Test 2
Input | Output |
---|---|
5 5 | 1/1 |
Test 3
Input | Output |
---|---|
9 12 | 234 |
Test 4
Input | Output |
---|---|
3 5 | 3/5 |
Test 5
Input | Output |
---|---|
14750533 22725185 | 2107219/3246455 |
题目分析
所见即所得,直接上代码。
解题代码
我写的代码:
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
x = int(input())
y = int(input())
def hcf(x,y):
if x>y:
smaller=y
else:
smaller=x
for i in range(1,smaller+1):
if ((x%i==0) and (y%i==0)):
h=i
return h
# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
h1=hcf(x,y)
x1=x//h1
y1=y//h1
print(("%d/%d")%(x1,y1))
大佬的代码(一个来自保加利亚的老哥):
from fractions import Fraction
numerator = int(input())
denominator = int(input())
# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
f=Fraction(numerator, denominator)
print(("%d/%d")%(f.numerator,f.denominator))
总结
1.Python range() 函数用法
2.Python3 print() 函数用法总结
3.python中进行分数fraction()运算