Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me about loops
#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


Messages In This Thread
Help me about loops - by aliwien - Mar-15-2021, 01:57 PM
RE: Help me about loops - by buran - Mar-15-2021, 02:11 PM
RE: Help me about loops - by aliwien - Mar-15-2021, 02:24 PM
RE: Help me about loops - by buran - Mar-15-2021, 02:54 PM

Forum Jump:

User Panel Messages

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