If you type Python incorrectly, it repeats

Asked 2 years ago, Updated 2 years ago, 14 views

while True:
    def std_weight(height,gender):
        ifgender == "Men":
            return height * height * 22
        elifgender == "Woman":
            return height * height * 21
        else:
            print("You have entered it incorrectly.")
    break
print("Please enter the key (excluding cm): ")
height = int(input())

print("Please select a gender". Male or female : ")
gender = str(input())

weight = round(std_weight(height / 100, gender), 2)
print("The standard weight of height {0} cm {1} is {2} kg."format(height,gender,weight))

I was studying while watching YouTube, and I have a question. If I put a different value between the key input part and the gender part, I want to keep repeating the phrase, what should I do?

python

2022-09-20 21:40

1 Answers

l = ["Boy". "Woman"]
while True:
    gender = str(input())
    if gender in l:
        break

In the case of gender, it is relatively simple in the above way.

But the key depends on how much other value you're talking about.

Do I just need to get a number? Should we be within the range of what we think is height?

Of course, either way, you just have to filter it well with conditional sentences.

Basically, it's possible in a gender-like way, so think about it Haha


2022-09-20 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.