Question 5: Error & Debugging
The code below crashes. I've given you the code and the error.
a. Explain why this code crashes.
b. What would you do to fix the code (in other words, rewrite the code that crashes)?
1 def main():
2 num = input("What's your favorite number? ")
3 newNum = num + 13
4 print("The sum of our favorite numbers is:",newNum)
5
6 main()
Traceback (most recent call last):
File "c:\Users\carrold\Downloads\testingCode.py", line 6, in <module>
main()
File "c:\Users\carrold\Downloads\testingCode.py", line 3, in main
newNum = num + 13
~~~~~~~~~~~
TypeError: can only concatenate str (not "int") to str