Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me about loops
#1
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.
Reply
#2
So, what have you tried so far? What particular problem you cannot solve on your own?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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)
Reply
#4
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
Output:
Number of cases: 150 Percentage increase: 50 1) 150 2) 225 3) 337 4) 505 5) 757 6) 1135 7) 1702 8) 2553
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

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