Help me about loops - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Help me about loops (/thread-32903.html) |
Help me about loops - aliwien - Mar-15-2021 Hello everybody, I want the project about loops and I need your help. My desire is: (a) (b) 1) 150 2) 300 3) 450 4) 600 My purpose increment columns a and b in the same while code. I'll appreciate it if you help me, thanks. RE: Help me about loops - buran - Mar-15-2021 So, what have you tried so far? What particular problem you cannot solve on your own? RE: Help me about loops - aliwien - Mar-15-2021 (Mar-15-2021, 02:11 PM)buran Wrote: So, what have you tried so far? What particular problem you cannot solve on your own? I wrote the code below. As you can see, I could write the b column but I couldn't write the a column. How can I write column a? def artış(x, r): y = x*((r/100)+1) return y h = 0 a = float(input('Number of cases: ')) b = float(input('Percentage increase: ')) while a < 30001: print(a) a = artış(a, b) RE: Help me about loops - buran - Mar-15-2021 number of issues: you start with a being, number of cases, while in the previous post that is b column.what is h? you claim you cannot write a column, but you print a? I guess there is some confusion between a and b in the previous example and here.def calculate(cases, rate): return int(cases * (rate / 100 + 1)) n = 1 cases = int(input('Number of cases: ')) # do you really want a float for cases rate = float(input('Percentage increase: ')) while cases <= 3000: print(f'{n}) {cases}') cases = calculate(cases, rate) n += 1 in your original post the column b increase by fixed number - 150, not by given percent in which case you can use a for loop
|