The first day of the # # learning python
dear friends hello, everyone, today is the first day, I went to the CSND too I really started to learn python on the first day, then I will be here to record every day I learn python process, hope you can and I together to witness the process, together refueling efforts! In learning the simple input
print and output input , I tried to write statement
A calculation of weight summary
Reference
xiaoming is 1.75, weight 80.5 kg, please according to BMI formula (weight divided by the square of height) help xiao Ming his BMI calculation, and according to BMI: Been less than 18.5: 18.5-25: normal 25 to 28:28-32: overweight obesity is higher than 32: severe obesity The code is as follows: pythonWeight=80 Height=1.75 Bmi=weight/height ^ 2 If bmi<18.5: Print (" low ") If 18.5 & lt;=bmi>=25: Print (" normal ") Elif 25 & lt; Bmi> 28: Print (" overweight ") Elif 28 & lt;=bmi>=32: Print (" obesity ") Elif bmi> 32: Print (" severe obesity ") But after execution, discovered the mistake The File line 3, the in & lt; module> Bmi=weight/height ^ 2 TypeError: unsupported operand type (s) for ^ : 'float' and 'int' Problem is ^ the square error, I thought because I square number on the front, the results after me in the back or error How to do? I will go to the CTRL c and CTRL v ask baidu Originally I will ^ symbol in the python wrong understanding for index operation, the index used in python (* *) or commonly used computing pow (a, b) The ^ in python is not the meaning of index computing ^ is the bitwise xor logical operator When I put the ^ modified into * *, run a success! Then I'm going to let this program can be input, rather than a simple implementation and output So I wrote a piece of code weight=input (" weight: ") Height: height=input (" ") Bmi=weight/height * * 2 If bmi<18.5: Print (" low ") If 18.5 & lt;=bmi>=25: Print (" normal ") Elif 25 & lt; Bmi> 28: Print (" overweight ") Elif 28 & lt;=bmi>=32: Print (" obesity ") Elif bmi> 32: Print (" severe obesity ") The reference File line3, in Bmi=weight/height ^ 2 TypeError: unsupported operand type (s) for/: 'STR' and 'STR' Yes, an error again, This is because the original input () returns the data type is STR , STR cannot be directly compared to an integer, must first put the STR converted to an integer, Do how? Use int () function can solve Then I put the code to the pythonA=input (" weight ") B=input (" height ") Weight=(int) (a) Height=int (b) Bmi=weight/height * * 2 If bmi<18.5: Print (" low ") Elif 18.5 & lt;=bmi>=25: Print (" normal ") Elif 25 & lt; Bmi> 28: Print (" overweight ") Elif 28 & lt;=bmi>=32: Print (" obesity ") The else: Print (" severe obesity ") Performed under no problem, but when the number is decimal, an error again, Looks like int () does not support floating-point Numbers, so I was replaced by the float () it is no problem to perform, but I can't input numerical light only and normal two kinds of results, Don't know what went wrong, let me check for you tomorrow morning! * * Good night! * * CodePudding user response:
You judge the situation, need to change a little bit about the 18.5 & lt;=bmi & lt; 25= 25 & lt; Bmi & lt; 28 28 & lt;=bmi & lt; 32= In addition, the int () cannot convert decimal, such as' 80.5 ', a little change: Weight=float (a) Height=float (b) Good!!!!! I hope you can hold on, come on!!!!!! CodePudding user response:
Good, after using the code label, you have already surpassed all the new people in this BBS, insist on slowly, take an examination of a good school of computer science, taking good line CodePudding user response:
Thank you very much for your support, I will continue to work hard! CodePudding user response:
My adult college will graduate in July of next year, after graduation to take an undergraduate course,