Question: for python , how can I get a yes or no for this in regards to the variable choice or it repeats the question again?
for python , how can I get a yes or no for this in regards to the variable choice or it repeats the question again? In regard to this line...choice=str(input('Are you a new user? yes/no: '))
def main():
print('Welcome to your exercise app!')
choice=str(input('Are you a new user? yes/no: ')) if('y' in choice.lower()):
#delete the previously created file. if(os.path.exists('exapp.txt')): os.remove ('exapp.txt')
try: goal=int(input(' Please enter your fitness choice enter 1 for Gain Weight: or 2 for Lose Weight: ')) if(goal==1): gain_weight()#function call gain_weight elif(goal==2): lose_weight()#function call lose_weight else: print('Please enter correct choice. Now exiting.') except ValueError: print('You have entered a nonnumerical value. Please restart the program again and choose 1 or 2')
except: print('Some exception occurred. Please contact exercise app.')
else: #open existing file try: f=open('exapp.txt','r')#fout if writing into file, fin for reading, f casually goal=f.readline()[:-1] f.close() if(goal=='gain'): gain_weight() elif(goal=='lose'): lose_weight() else: print('No previous user data found. Please start as a new user.') os.remove('exapp.txt') except FileNotFoundError: print('No previous user data found. Please start as a new user.')
#end of this function main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
