I don't understand why the repetition for should go in.

Asked 2 years ago, Updated 2 years ago, 20 views

Numbers consisting of 4, 6, and 8 should be matched like this.

Number - String
4 - love
8 - smile
6 - kiss

For example, If you enter 48686 in the variable, The result is that the value should be like lovesmilekisssmilekiss.

I'm asking you to create a YoonHA() function that tells me the password.

First of all, I thought I should use the Dict function

    def yoonHa(nums):
        word = {4:"love", 8:"smile", 6:"kiss"}
        When password = 4, 8, 6 is entered, an expression must be created that pops out
        return password

After this structure came out

    nums = int(input())
    print(yoonHa(nums))

I think this will work. The person who gave the question said that we need to solve it using the for function I know the def and word function, but I don't know how to make it after that.

I don't understand why the for function is a repeat statement, but I don't understand why the repeat statement should go in. I don't think it's a difficult question, but I'm asking because I don't have a place to ask because I'm self-taught.

python

2022-09-20 14:44

1 Answers

You have to do something repetitively → First of all, for. Just remember that it's just like that's all. The reason for the existence of the for statement in the first place is the repetition (to be exact, 'triple' – iteration).

So what's going to be repeated in this question, will for come up? It's a simple story. You have to repeat the task of checking each letter of the input value. For example, if you receive the string "48686", you'll have to look for it in word repeatedly from the first "4" to the last "6".

Fortunately, on Python, it's so easy to navigate every letter of a string.

for x in "some_string" :
    print(x)

When programming, you should be able to think about why and when you need a form of for. To exaggerate a little, there are only three "controls" in programming: for, if, and else. Take a good look at the question again! Good luck to you.


2022-09-20 14:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.