Advertisement
jspill

webinar-input-patters-2023-01-14

Jan 14th, 2023
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. # Webinar Input Patterns Jan 14 2023
  2.  
  3. # input() ALWAYS returns a string
  4. # myInput = input()
  5. #
  6. # but we might want to change it to something else...
  7. # myVar = input()
  8. # print(type(myVar))
  9.  
  10.  
  11. # 1 Recast a numeric string into an int or float
  12. # 2 Breaking up a long string into a list of smaller strings
  13. # 3 Break up a string containing numeric chars into a list of
  14. #       recast ints or floats
  15. # 4 One value tells you how many times to call input()
  16. # 5 We DON'T KNOW how many times to call input(), but we know
  17. #       a sentinel value to stop
  18.  
  19. # 1 Recast a numeric string into an int or float
  20. # myInput = input()
  21. # myInput = "5" # input()
  22. # #yInput = int(myInput)
  23. # print(myInput, type(myInput).__name__)
  24. # myInput = int(input()) # float(input())
  25.  
  26. # 2 Breaking up a long string into a list of smaller strings
  27. # "Pat Silly Doe"
  28. # # myInput = input()
  29. # myInput = "Pat Silly Doe"
  30. # strList = myInput.split()
  31. # print(strList)
  32.  
  33. # 3 Break up a string containing numeric chars into a list of
  34. #       recast ints or floats
  35. # 10 5 3 21 2
  36. # myInput = "31 333 2 78 92"
  37. # strList = myInput.split()
  38. # print(strList)
  39. # numList = []
  40. # for num in strList:
  41. #     numList.append(int(num))
  42. #
  43. #
  44. # # You could do this as a LIST COMPREHENSION
  45. # # [expression for item in other container]
  46. # numList = [int(num) for num in strList]
  47. # print(numList)
  48.  
  49. #4 One value tells you HOW MANY TIMES to call input()
  50. # ... inputs:
  51. # 5
  52. # 30.0
  53. # 50.0
  54. # 10.0
  55. # 100.0
  56. # 65.0
  57.  
  58. # numValues = int(input())
  59. numValues = 5
  60. floatValues = []
  61.  
  62. # for n in range(numValues): # [0, 1, 2, 3, 4]
  63. #     nextInput = float(input())
  64. #     floatValues.append(nextInput)
  65. # print(floatValues)
  66.  
  67.  
  68. # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE
  69. # March 1, 1990
  70. # April 2 1995
  71. # 7/15/20
  72. # December 13, 2003
  73. # -1
  74.  
  75. myInput = input()
  76. # THEN we can loop...
  77. while myInput != "-1": # myInput < 0:
  78.     # do the stuff for this problem
  79.  
  80.     myInput = input()
  81.  
  82.  
  83.  
  84. # Student questions
  85. # multiple quit commands
  86. # Done, done, d, quit
  87. myInput = input()
  88. # while myInput != "Done" and myInput != "done" and myInput != "d":
  89. quitCommands = ["Done", "done", "d", "quit"]
  90. while not myInput in quitCommands:
  91.     # do your stuff
  92.     myInput = input()
  93.  
  94. # 11.18
  95. # 25 51 0 200 33 # from nums like this
  96. # 0 50 # get those in this range, inclusive
  97. numsList = input().split()
  98. numsList = [int(num) for num in numsList]
  99. startStopList = input().split()
  100. start = int(startStopList[0])
  101. stop = int(startStopList[1])
  102.  
  103. for num in numsList:
  104.     if start <= num <= stop:
  105.         print(num, end=" ") # normally we wouldn't stop without a \n, but note in questions says to do this
  106.  
  107.  
  108.  
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement