- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathlargest_of_very_large_numbers.py
48 lines (41 loc) · 1.28 KB
/
largest_of_very_large_numbers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Author: Abhijeeth S
importmath
defres(x, y):
"""
Reduces large number to a more manageable number
>>> res(5, 7)
4.892790030352132
>>> res(0, 5)
0
>>> res(3, 0)
1
>>> res(-1, 5)
Traceback (most recent call last):
...
ValueError: math domain error
"""
if0notin (x, y):
# We use the relation x^y = y*log10(x), where 10 is the base.
returny*math.log10(x)
elifx==0: # 0 raised to any number is 0
return0
elify==0:
return1# any number raised to 0 is 1
raiseAssertionError("This should never happen")
if__name__=="__main__": # Main function
# Read two numbers from input and typecast them to int using map function.
# Here x is the base and y is the power.
prompt="Enter the base and the power separated by a comma: "
x1, y1=map(int, input(prompt).split(","))
x2, y2=map(int, input(prompt).split(","))
# We find the log of each number, using the function res(), which takes two
# arguments.
res1=res(x1, y1)
res2=res(x2, y2)
# We check for the largest number
ifres1>res2:
print("Largest number is", x1, "^", y1)
elifres2>res1:
print("Largest number is", x2, "^", y2)
else:
print("Both are equal")