Reputation: 557
I was online at this amazing site for equivalent ratios. I would love to mimic or do the same as an output in python, but its a bit over my skills.
Can you help me put it in this format, here is what the first 3 pairs would look like in the output in python, if you can help me please? I'm using python37
1 : 5618 2 : 11236 3 : 16854
Here is the site that does what I want: https://goodcalculators.com/ratio-calculator/
Here is my code so far but I hope someone can help me so it prints out in a nice fancy format or just maybe a cool list of numbers in equivalent ratio format:
It is throwing an error and I don't know why, and this is the error:
ValueError: invalid literal for int() with base 10: ' Enter 1st number for ratio calculation: '
while True:
a = input(int(' Enter 1st number for ratio calculation: '))
b = input(int(' Enter 2nd number for ratio calculation: '))
r = ( a/b and b/b)
print(r)
Upvotes: 3
Views: 2154
Reputation: 7224
Your ints should be first:
while True:
a = int(input(' Enter 1st number for ratio calculation: '))
b = int(input(' Enter 2nd number for ratio calculation: '))
r = ( a/b and b/b)
print(r)
For the calculator you can do something like this:
list_numbers={}
ratio1 = 1
ratio2 = 3698
for x in range(1,100):
list_numbers.update({ratio1*x: ratio2*x})
Upvotes: 4
Reputation: 953
There are two functions according to the versions of the python you have on your system. Python3 has input() and python2 has raw_input() which returns the string objects only. so that you need to explicitly convert it to the integer. For python3 you can do as below and for python2 you can use eval() function ahead of raw_input() so that you can evaluate the expression.
while True:
a = int(input(' Enter 1st number for ratio calculation: '))
b = int(input(' Enter 2nd number for ratio calculation: '))
r = ( a/b and b/b)
print(r)
Python2:
x=1
print eval('x+1') ==> 2
Upvotes: 2