Advertisement
jspill

webinar-python-input-patterns-2022-09-10

Sep 10th, 2022
1,263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. # Webinar Input Patterns
  2. # Sept 10, 2022
  3.  
  4. # input() ALWAYS returns a string
  5. # myInput = input()
  6. #
  7. # but we might want to change it to something else...
  8.  
  9. # 1 Turn a numeric string into an int or float
  10. # 2 Breaking up a long string into a list of smaller strings
  11. # 3 Break up a string containing numeric chars into a list of
  12. #       recast ints or floats
  13. # 4 One value tells you how many times to call input()
  14. # 5 We DON'T KNOW how many times to call input(), but we know
  15. #       a sentinel value to stop
  16.  
  17. # 1 Turn a numeric string into an int or float
  18. # myInput = input()
  19. # myInput = "5"
  20. # myInput = int(input()) # float(input())
  21.  
  22. # 2 Breaking up a long string into a list of smaller strings
  23. # myInput = "Pat Silly Doe" # input()
  24. # strList = myInput.split() # str split() turns a long str into a list of short str
  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 567 2 93 6" # input()
  31. # strList = myInput.split()
  32. # print(strList)
  33. # numList = []
  34. # for num in strList:
  35. #     numList.append(int(num))
  36. # print(numList)
  37.  
  38. # you could do this with a LIST COMPREHENSION
  39. # [expression for item in other container]
  40. # myInput = "2 34 87 234 99" # input().split()
  41. # strList = myInput.split()
  42. # numList = [int(num) for num in strList]
  43. # print(numList)
  44.  
  45. # 4 One value tells you how many times to call input()
  46. # for example 6.17
  47. # example inputs for 6.17:
  48. # 5
  49. # 30.0
  50. # 50.0
  51. # 10.0
  52. # 100.0
  53. # 65.0
  54.  
  55. # numValues = 5 "# int(input())
  56. # floatValues = []
  57. # for n in range(0, numValues): # first input
  58. #     nextInput = float(input())
  59. #     floatValues.append(nextInput)
  60. #
  61. # # to finish out that Lab...
  62. # theMax = max(floatValues)
  63. # for num in floatValues:
  64. #     print("{:.2f}".format(num/theMax))
  65.  
  66. # 5 We DON'T KNOW how many times to call input(), but we know
  67. #       a sentinel value to stop
  68. # Lab 33.15
  69. # March 1, 1990
  70. # April 2 1995
  71. # 7/15/20
  72. # December 13, 2003
  73. # -1
  74.  
  75. # ask for the FIRST input()
  76. myInput = input()
  77. # THEN we can loop...
  78. while myInput != "-1":
  79.     # do our stuff
  80.  
  81.     myInput = input() # last thing... get the next input()
  82.  
  83. # multiple quit commands
  84. # Done, done, d
  85. myInput = input().strip() # I haven't been stripping inputs, but it's always a good idea!
  86. # while myInput != "Done" and myInput != "done" and myInput != "d":
  87. quitCommands = ["Done", "done", "d"]
  88. while myInput not in quitCommands:
  89.     # do your stuff
  90.  
  91.     myInput = input().strip()
  92.  
  93.  
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement