Question: In Python, how could I take this portion of code and make a function out of it called something like Def loseWeight(): I'm wanting to

In Python, how could I take this portion of code and make a function out of it called something like Def loseWeight():

I'm wanting to create a separate file for the functions to be called to make the code more manageable. Please see code and image below...

from operator import eq from operator import ge from operator import le

#asking user input in loop it will continue until correct value

while True:

overallGoal= str(input('Do you desire to lose weight or gain muscle? Please type in lose weight or gain muscle.')) if eq(overallGoal.lower(), "lose weight"):

while True:#loop for entering int values

try:

currentWeight = int(input("Please enter current weight in pounds. "))

idealWeight = int(input("Please enter the weight you wish to obtain ultimately. ")) if ge(idealWeight, currentWeight): print("The goal weight must be less than current weight. Please reenter information.")

else:

break #The goal weight must be less than current exit from loop

except ValueError:#if invalid input will be given it will ask again

print("invalid entry. Please enter numeric value only.")

break#breaking loop on valid entryIn Python, how could I take this portion of code and make

from operator import eq from operator import ge from operator import le #asking user input in loop it will continue until correct value while True: overallGoal- str(input ( Do you desire to lose weight or gain muscle? Please type in lose weight or gain muscle. ') if eq(overallGoal.lower(), "lose weight"): while True#loop for entering int values try: currentWeight = int(input("Please enter current weight in pounds. ")) idealWeight - int(input( "Please enter the weight you wish to obtain ultimately. ")) if ge(idealweight, currentweight): print("The goal weight must be less than current weight. Please reenter information.") else: break #The goal weight must be less than current exit from loop except ValueError:#1f invalid input will be given it will ask again print("invalid entry. Please enter numeric value only.") break#breaking loop on valid entry

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!