Advertisement
jspill

webinar-input-patterns-2023-07-15

Jul 15th, 2023
1,262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | None | 0 0
  1. # Webinar Input Patterns July 15 2023
  2.  
  3. # input() ALWAYS returns a string
  4. # myInput = input() # that myInput var is definitely a str!
  5.  
  6. # but we might want to change it to something else...
  7.  
  8. # 1 Recast a numeric string into an int or float
  9. # 2 Breaking up a long string into a list of smaller strings
  10. # 3 Break up a string containing numeric chars into a list of
  11. #       recast ints or floats
  12. # 4 One value tells you how many times to call input()
  13. # 5 We DON'T KNOW how many times to call input(), but we know
  14. #       a sentinel value to stop
  15.  
  16.  
  17. # 1 Recast a numeric string into an int or float
  18. # looks like a number...  5 but it's really the string "5"
  19. # easy, recast
  20. # myInput = int(input()) # or float(input()) if you want a float
  21.  
  22. # 2 Breaking up a long string into a list of smaller strings
  23. # "Pat Silly Doe"
  24. # myInput = input()
  25. # strList = myInput.split()
  26. # strList = input().split() # could do it one step
  27. # print(strList)
  28.  
  29. # getting a series of numbers...
  30. # 12 44 67 23
  31. # myInput = "12 44 67 23" # input()
  32. # strList = myInput.split()
  33. # print(strList)
  34. # # traditional for loop for new list
  35. # numList = []
  36. # for num in strList:
  37. #     numList.append(int(num))
  38. # # or list comprehension for new list
  39. # numList = [int(num) for num in strList]
  40. # print(numList)
  41. #
  42. # # 4 One value tells you HOW MANY TIMES to call input()
  43. # # 5 # so 5 more pieces of data coming in...
  44. # # 30.0
  45. # # 50.0
  46. # # 10.0
  47. # # 100.0
  48. # # 65.0
  49. #
  50. # numVals = int(input())
  51. # floatList = [] # fill this basket...
  52. #
  53. # for num in range(numVals): # do this 5 times
  54. #     # get each next input, do your stuff
  55. #     nextInput = float(input())
  56. #     floatList.append(nextInput)
  57. # print(floatList)
  58. #
  59. # Question on "printing a list without brackets"... which isn't necessarily something you need to do
  60. # for n in floatList:
  61. #     print(n, end=" ")
  62. # print() # get the line return back, unless a question says otherwise
  63. #
  64. # # " ".join(listOfStrings)
  65. # print(" ".join([str(num) for num in floatList]))
  66.  
  67. # Question on range(len())
  68. # myList = ["Scooby", "Shaggy", "Velma", "Daphne", "Fred", "Scrappy"]
  69. # for item in myList:
  70. #     print(item)
  71. #
  72. # for n in range(len(myList)):
  73. #     print(n)
  74. #     print(myList[n])
  75.  
  76. # back to Input Patterns...
  77.  
  78. # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE
  79. # this is a WHILE loop condition
  80.  
  81. # ask for the FIRST input()
  82. # myInput = input()
  83. # # then set up a WHILE LOOP
  84. # while myInput != "-1": # or whatever value tells you to stop
  85. #     # do what you need with that input...
  86. #
  87. #     # get the next input
  88. #     myInput = input()
  89.  
  90. # multiple quit commands
  91. # myInput = input()
  92. # quitCommands = ["quit", "done", "d"] # put them in a list to avoid many conditions joined by an OR
  93. # while not myInput in quitCommands:
  94. #     print(f"I got the command: {myInput}")
  95. #     myInput = input()
  96. # print("OK. Done!")
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement