Home > other >  Beginners a doubt about input used in python
Beginners a doubt about input used in python

Time:09-27

I am a self-taught python beginners, met a think impassability place today, a great god, please give directions,
Behind this set of code below, there are two implementation defined function, their function is the same, I just want to give the first part of the specified argument, the second part with the input input parameters, but it was a mystery to me, the result of the specific code is as follows,
Def add (a, b) :
Print (" ADDING f {a} + {b} ")
The return of a + b

Age=add (30, 5)
Print (f "age: {age}")

Age2=add (input (), input ())
Print (f "age2: {age2}")

The running result is
ADDING: 30 + 5
Age: 35
30 # this number is I manually input the parameters of the
5 # is the same number I manually input the parameters of the
ADDING: 30 + 5
Age2:305

The great god, don't know I write clear? According to my understanding, and finally the result of the execution should be the same, why is the age of 35, age2 was 305, why is 30 + 5 305?

CodePudding user response:

Input is a string, need to turn the integer

Age2=add (int (input ()), int (input ()))

CodePudding user response:

reference 1/f, ice wind of reply:
input string, need to turn the integer

Age2=add (int (input ()), int (input ()))

Yes, it is you, thank you, do you have any recommended books or method? You can see come out, my foundation is almost zero, how can learn less difficult?

CodePudding user response:

I generally recommend Liao Xuefeng python tutorial https://www.liaoxuefeng.com/wiki/1016959663602400
The key still practising more

CodePudding user response:

Ok, thank you

CodePudding user response:

User input is a string, and you'd better change the variable naming, don't be a letter
  • Related