Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, I am trying to figure out how to only accept a weight that is less than the current weight and then reask(loop back

In Python, I am trying to figure out how to only accept a weight that is less than the current weight and then reask(loop back to) the question regarding ideal weight until user gives a response that is below the current weight. How do I do this? Attached is image and I copy and pasted the code.

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.")

break

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 entry

image text in transcribed

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: currentieight = 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 infornation. break 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 entry

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago