+ 1
What is the best time for type conversion?
What is the best time to convert a variable to the correct type? Is it best to always convert it straight away? Does it depend on the situation? Here is an example: def age100(): name = input("Please enter your name.") age = input("Please enter your age.") copies = input("How many copies would you like?") result = name+", you will turn 100 in the year "+str(2120 - int(age))+". \n" print(result*int(copies)) age100() As you can see, I did most of my conversion in the later stages, whereas most other people did it at the input stages... Which is better and why? I'm new to programming, so any other feedback on my code is welcome!
2 Answers
+ 3
Suchet Jones Of course doing it in input is more convenient
Becuase converting it further in print function create a mess which make ur code little bit unreadable
Or hard to read and debug
So convert them in time of input
+ 1
Ok, thanks. That's what I thought. Unless, the variable needs to be used somewhere else in the code in it's original form, I guess... I'll do it that way next time..