jspill

webinar-python-input-patterns-2022-11-12

Nov 12th, 2022
1,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. # Webinar Input Patterns Nov 12 2022
  2.  
  3. # input() ALWAYS returns a string
  4. # myInput = input()
  5. #
  6. # but we might want to change it to something else...
  7.  
  8. # 1 Turn 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. # 1 Turn a numeric string into an int or float
  17. # myInput = input()
  18. # myInput = "5" # input()
  19. # myInput = int(input()) # float(input())... int(input().strip())
  20.  
  21. # 2 Breaking up a long string into a list of smaller strings
  22. # myInput = input()
  23. # myInput = "Pat Silly Doe"
  24. # strList = myInput.split()
  25. # print(strList)
  26.  
  27. # 3 Break up a string containing numeric chars into a list of
  28. #       recast ints or floats
  29. # Lab 28.11... 10 5 3 21 2
  30. # myInput = "31 333 2 78 92"
  31. # strList = myInput.split()
  32. # print(strList)
  33. # numList = []
  34. # for num in strList:
  35. #     numList.append(int(num))
  36. #
  37. #
  38. # # You could do this as a LIST COMPREHENSION
  39. # # [expression for item in other container]
  40. # numList = [int(num) for num in strList]
  41. # print(numList)
  42.  
  43.  
  44. #4 One value tells you HOW MANY TIMES to call input()
  45. # like Lab 6.17
  46. # ... inputs:
  47. # 5
  48. # 30.0
  49. # 50.0
  50. # 10.0
  51. # 100.0
  52. # 65.0
  53.  
  54. # numValues = int(input())
  55. # numValues = 5
  56. # floatValues = []
  57. #
  58. # for n in range(numValues): # [0, 1, 2, 3, 4]
  59. #     nextInput = float(input())
  60. #     floatValues.append(nextInput)
  61. # print(floatValues)
  62.  
  63.  
  64. # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE
  65. # Lab 33.15
  66. # March 1, 1990
  67. # April 2 1995
  68. # 7/15/20
  69. # December 13, 2003
  70. # -1
  71.  
  72. # ask for the FIRST input()
  73. myInput = input()
  74. # THEN we can loop...
  75. while myInput != "-1": # not the int -1 but the str "-1"... our loop will not ever stop if we're testing the wrong one!!!
  76.     # do our stuff
  77.  
  78.     myInput = input() # last in loop, grab input for next iteration
  79.  
  80. # multiple quit commands
  81. # Done, done, d, quit
  82. # while myInput != "Done" and myInput != "done" and myInput != "d":
  83. quitCommands = ["Done", "done", "d", "quit"]
  84. while not myInput in quitCommands:
  85.     # do your stuff
  86.     myInput = input()
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment