How should I approach this?

I’m not sure how to approach this. Anyone have any ideas?

def multiplication_table(number):
    # Initialize the appropriate variable
    ___ = ___

    # Complete the while loop condition.
    while ___:
        result = number * multiplier 
        if  result > 25:
            # Enter the action to take if the result > 25
        print(str(number) + "x" + str(multiplier) + "=" + str(result))
        # Increment the appropriate variable
        ___ += 1


# Should print:

# 3x1=3

# 3x2=6

# 3x3=9

# 3x4=12

# 3x5=15


# Should print:

# 5x1=5

# 5x2=10

# 5x3=15

# 5x4=20

# 5x5=25


# Should print:

# 8x1=8

# 8x2=16

 # 8x3=24

You’re supposed to write a function. The task has been made easier by them providing a skeleton of said function. All you have to do is fill in the blanks.

what should i call the variable to?

Anything you want - the code will work the same. It is important that you try yourself rather than getting others to do your homework.

I understand that. I just don’t know how to approach it. It’s hard to me

You need to look for some examples of while loops - just google it. Read about how while loops work and then write your code and see what happens.

So far all you have done is to post illegible photos of your computer screen (which is considered quite rude in this forum). You have not showed an attempt to write a single line of code. As I said, look at examples, copy them and see what happens, and that way you will learn. If you write some code and it does not work the way you expect that is the time to ask for help in the forum.

I hope this helps.

1 Like

First, I need to ask a few questions to establish your understanding.

  1. When the code runs, how many times do you think the loop should run?

  2. Each time the loop runs, what do you think should appear in the output?

  3. Where the code says

    , do you understand how this relates to the example output you were given? How do you think it relates?

  4. According to that understanding, which of those values do you think should change each time through the loop - number, or multiplier?

  5. In plain English, what do you think is “the action to take if the result > 25”? What should happen, if that is true (i.e., if the result is greater than 25)?

1 Like