Home > other >  [small white consult post] the if function USES about Python
[small white consult post] the if function USES about Python

Time:09-29


As is shown above, I can not judge in Chinese red box

CodePudding user response:


No permissions correction, image upload repeated

CodePudding user response:

Problem #

Write guess=int (temp) what is the purpose?

# a solution

Temp=input (' who is your favorite? ')
Guess=int (temp)

Change

Guess=input (' who is your favorite? ')

CodePudding user response:

Not red box where you can't use Chinese to judge, but guess=int (temp) when there is a problem!
If you run the program input is "I", when the temp is a non-numeric character string, it must be not casts!
Obtained through input variable values and make the int (temp) is the premise of not an error, the temp must be a pure integer (even no floating point) in the form of a string,

CodePudding user response:

reference paullbm reply: 3/f
is not red box where you can not judge in Chinese, but guess=int (temp) when there is a problem!
If you run the program input is "I", when the temp is a non-numeric character string, it must be not casts!
Obtained through input variable values and make the int (temp) is the premise of not an error, the temp must be a pure integer (even no floating point) in the form of a string,

Oh ~ ~ see that behind the int must with pure integer Numbers

CodePudding user response:

refer to the second floor. So ne response:

# problem
Write guess=int (temp) what is the purpose?

# a solution

Temp=input (' who is your favorite? ')
Guess=int (temp)

Change

Guess=input (' who is your favorite? ')

Ok, thank you, I know how the matter now

CodePudding user response:

Integer and string cannot be compared, certainly have a different type
I will use your code in error: invalid literal for the int () with base 10
Of course, if the input is an integer that get the results of the else
  • Related