##### How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000
 How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades Not Blown Up Yet Posts: 58 Threads: 19 Joined: Apr 2018 Reputation: 1 Nov-20-2019, 04:47 AM (This post was last modified: Nov-20-2019, 04:48 AM by Pleiades.) 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? 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)``` Reply Posts: 2,813 Threads: 33 Joined: Jan 2018 Reputation: 256 Nov-20-2019, 04:52 AM Replace `input(int(...))` with `int(input(...))`. Currently you are trying to convert a sentence into an integer and that puzzles the python interpreter. Reply ChislaineWijdeven Programmer named Tim Posts: 13 Threads: 0 Joined: Nov 2019 Reputation: 0 Nov-20-2019, 10:52 AM Hi! Check lines 2 and 3, you mixed up input and int, it should be vice versa: int(input(...)). Good luck! Reply Pleiades Not Blown Up Yet Posts: 58 Threads: 19 Joined: Apr 2018 Reputation: 1 Nov-21-2019, 07:26 AM (This post was last modified: Nov-21-2019, 07:26 AM by Pleiades.) Thanks guys however I'm trying to create a clean print though. This print job repeats, and with a little help at stackexcange along with my modification we got it to work. However, checkout the print feature. Can anyone help me with a single quality print here. Here is the code I have. Run it and see what it prints. Also: While I print using this python37 code it repeats till the end and its slow. I really need it to print super fast. Also I would like to divide the first number it finds before the colon and output the number that it is associated with after the colon. For instance the program finds this ratio pair ( 8978:1445580) in the set after going through an amount of numbers and I decided to divide it like this 8978/8978 then the output should print (1445580). Or maybe it just matches 8978 and prints (1445580) as the output. Is this possible? It does seem programmable, but my skills are a little weak in this area and I could use some help. Thanks very much for any help! :) Here is the code I'm working with: ```while True: list_numbers={} a = int(input(' Enter 1st number for ratio calculation: ')) b = int(input(' Enter 2nd number for ratio calculation: ')) y = int(input(' Enter y start range: ')) n = int(input(' Enter n end range: ')) for x in range(y,n): list_numbers.update({a*x: b*x}) print(list_numbers)``` Reply DeaD_EyE Da Bishop Posts: 1,554 Threads: 5 Joined: May 2017 Reputation: 181 Nov-21-2019, 08:03 AM (This post was last modified: Nov-21-2019, 08:03 AM by DeaD_EyE.) Only thress changes. First you assign for each iteration the name `list_numbers` to an empty dict. You have to initialize this outside of the loop to prevent this. Instead of using a loop, put this code in a function. This function asks only one time. To repeat this, call this function somewhere else in a while-True loop. ```def ratio(): list_numbers={} a = int(input(' Enter 1st number for ratio calculation: ')) b = int(input(' Enter 2nd number for ratio calculation: ')) y = int(input(' Enter y start range: ')) n = int(input(' Enter n end range: ')) for x in range(y,n): list_numbers.update({a*x: b*x}) return list_numbers```The third change is the print function. Print your results, after you've collected them, otherwise you'll get as first result, then the first two and etc... This did work with only one result, because the dict was replaced by a new empty dict for each iteration. But the code has been changed into a function, so the results should be returned and not printed. Just having one function, which does only one thing, it's easier for later reuse in code and is also easier to change. My code examples are always for Python >=3.6.0 Almost dead, but too lazy to die: https://sourceserver.info All humans together. We don't need politicians! Reply Pleiades Not Blown Up Yet Posts: 58 Threads: 19 Joined: Apr 2018 Reputation: 1 Nov-21-2019, 09:02 PM (This post was last modified: Nov-21-2019, 09:02 PM by Pleiades.) @Anyone How do I print a specific denominator of a ratio? The code outputs ratios in this format of a dictionary like this: {1: 8978, 2: 17956, 3: 26934, 4: 35912, 5: 44890, 6: 53868, 7: 62846, 8: 71824, 9: 80802} I would like to print the denominator of a ratio by using a specific input. For instance, I want to use some unknown input for the program to find this ratio pair ( 5: 44890) and while going through a series of numbers in the dictionary during the codes processing; I would like it to print (44890) at the conclusion of its processing. while True: list_numbers={} a = int(input(' Enter 1st number for ratio calculation: ')) b = int(input(' Enter 2nd number for ratio calculation: ')) y = int(input(' Enter y start range: ')) n = int(input(' Enter n end range: ')) list_numbers = {(a*x): (b*x) for x in range(y,n)} print(list_numbers) ```while True: list_numbers={} a = int(input(' Enter 1st number for ratio calculation: ')) b = int(input(' Enter 2nd number for ratio calculation: ')) d = int(input(' Enter a number to divide ratio before colon: ')) y = int(input(' Enter y start range: ')) n = int(input(' Enter n end range: ')) list_numbers = {((a*x)%(d)): b*x for x in range(y,n)} print(list_numbers)``` Reply ndc85430 Da Bishop Posts: 1,240 Threads: 0 Joined: Apr 2017 Reputation: 76 Jul-01-2020, 03:53 PM (Nov-21-2019, 09:02 PM)Pleiades Wrote: {1: 8978, 2: 17956, 3: 26934, 4: 35912, 5: 44890, 6: 53868, 7: 62846, 8: 71824, 9: 80802} For instance, I want to use some unknown input for the program to find this ratio pair ( 5: 44890) and while going through a series of numbers in the dictionary during the codes processing; I would like it to print (44890) at the conclusion of its processing. I don't really understand what you're trying to do. How does the input relate to what you're trying to find? Imagine you didn't have a computer and had this collection of values written down on paper. How would you find the one you want? With quite small problems like this, you should be trying to figure out the steps in getting to the solution. Code will naturally follow from those (assuming you know the right code elements to implement your solution, but you need to start at finding the solution first). Reply

 Possibly Related Threads… Thread Author Replies Views Last Post adding numbers in a list Nickd12 2 87 Yesterday, 12:46 PM Last Post: Serafim Regular expression: return string, not list Pavel_47 3 73 Jan-14-2021, 11:49 AM Last Post: Pavel_47 Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 147 Dec-30-2020, 12:04 AM Last Post: MvGulik Print max numbers in a list jimmoriarty 1 263 Sep-25-2020, 07:29 AM Last Post: DPaul importing a list of numbers into python script barrypyth 8 604 Aug-22-2020, 09:10 PM Last Post: barrypyth Summing a list of numbers Oldman45 6 471 Jul-12-2020, 05:30 PM Last Post: Oldman45 Function to return list of all the INDEX values of a defined ndarray? pjfarley3 2 412 Jul-10-2020, 04:51 AM Last Post: pjfarley3 Topic: “Filter numbers with a list comprehension” (PyBite #107) Drone4four 4 483 Jun-11-2020, 08:31 PM Last Post: Drone4four Return prime numbers from range krzyfigh 2 413 Apr-20-2020, 08:08 PM Last Post: krzyfigh Assign the sum of 2 consecutive numbers in a list to a varibale Fenaz 3 561 Apr-05-2020, 10:30 PM Last Post: bowlofred

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020