Comments by "swallowedinthesea11" (@swallowedinthesea11) on "do you need to be good at MATH to learn Python? // Python RIGHT NOW!! // EP 3" video.

  1. 4
  2. 3
  3. 3
  4. 3
  5. 2
  6. 2
  7. 2
  8. 2
  9. 2
  10. 2
  11. 2
  12. 2
  13. 2
  14. 2
  15. 2
  16. 2
  17. 2
  18. 2
  19. 2
  20. 2
  21. 2
  22. 1
  23. 1
  24. 1
  25. 1
  26. 1
  27. 1
  28. 1
  29. Friendly tip: we now use the new f-strings which was introduced in version 3.8. Concatenation is pretty archaic, confusing to read, requires extra work, and so 1990s. That said, your error is in the following: You have to remember that the input function always returns a string data type. Hence why you got 11111111 because typing 1 is not an integer data type, it's a string data type '1' Notice the quotes; they signify that '1' is a string data type. print ("your " + order + " will cost " + (8 * Quantity) + "$ \n ") Because you're concatenating, you need to convert Quantity into an integer data type by using the integer function: print ("your " + order + " will cost " + ( 8 * int(Quantity) ) + "$ \n ") Now run it. Did you get an error? You have to go the extra step by converting the value into a string data type because concatenating only works for string data types by using the string function: print ("your " + order + " will cost " + str( ( 8 * int(Quantity) ) ) + "$ \n ") Now everything works. Using f-strings, it would look like this: print ( f"your {order} will cost { 8 * int(Quantity) } $ \n ") Read the following to learn more about f-strings: There is a rule when you want to concatenate a string data type with an integer data type: you can't concatenate different data types - the data type must be a string. You can use type coercion to convert an integer into a string using str(): characterAge = 500 print( 'Belle Delphine is ' + str(characterAge) ) # using str() to convert the integer print( 'Belle Delphine is', characterAge ) print( f'Belle Delphine is {characterAge}' ) # Above, f-strings are the newest way since version 3.8 VS version 3.6 that Mike used # As you can see, concatenation is archaic as f-strings are preferred. Just imagine how ugly having # a bunch of + symbols would be! Explanation: age = 46 print('Batman is aged: ' + age) ^Why do we get an error? Because Python hates concatenating different data types. In order to concatenate, all the data types must be a string data type! 46 is an integer data type. To change the type, we can use str(variable here): age = 26 print( 'Batman is aged: ' + str(age) ) print( f'Batman is aged {age}' ) age = input('How old are you? ') # let's input a number 100 print('Frank Castle is aged: ' + age) ^Why do we not get an error? Because Python loves concatenating the same data type which is the string data type. '100' is a string data type because it has the quotes. 100 looks like a number (just ask anyone you see) but whenever you use the input() function to get user input, anything the user types in automatically becomes a string data type.
    1
  30. 1
  31. 1
  32. 1
  33. 1
  34. 1
  35. 1
  36. 1
  37. 1
  38. 1
  39. 1
  40. 1
  41. 1
  42. 1
  43. 1
  44. 1
  45. 1
  46. 1
  47. 1
  48. 1
  49. 1
  50. 1
  51. 1
  52. 1
  53. 1
  54. 1
  55. 1
  56. 1
  57. 1
  58. 1
  59. 1
  60. 1
  61. 1
  62. 1
  63. 1
  64. 1
  65. 1
  66. 1
  67. 1
  68. 1
  69. 1
  70. 1
  71. 1
  72. 1
  73. 1
  74. 1