Advertisement
jspill

webinar-input-patterns-2023-02-11

Feb 11th, 2023
1,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. # Webinar Input Patterns Feb 11 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 a number...  5 so it's really "5"
  19. # myInput = int(input())
  20. # print(type(myInput))
  21.  
  22. # 2 Breaking up a long string into a list of smaller strings
  23. # "Pat Silly Doe"
  24. # myInput = "Pat Silly Doe" # input()
  25. # strList = myInput.split()
  26. # print(strList)
  27.  
  28. # 3 Break up a string containing numeric chars into a list of
  29. #       recast ints or floats
  30. # 10 5 3 21 2
  31. # myInput = "31 333 2 78 92" # input()
  32. # strList = myInput.split()
  33. # print(strList)
  34. # numList = []
  35. # for num in strList:
  36. #     numList.append(int(num))
  37. # print(numList)
  38.  
  39. # One value tells you HOW MANY TIMES to call input()
  40. # ... inputs:
  41. # 5
  42. # 30.0
  43. # 50.0
  44. # 10.0
  45. # 100.0
  46. # 65.0
  47.  
  48. # numValues = int(input())
  49. # floatList = []
  50. #
  51. # for n in range(0, numValues): # [0, 1, 2, 3, 4]
  52. #     nextInput = float(input())
  53. #     floatList.append(nextInput)
  54. # print(floatList)
  55.  
  56.  
  57. # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE
  58. # this is a WHILE loop condition
  59.  
  60. # ask for the FIRST input()
  61. myInput = input()
  62. # THEN we can loop...
  63. while myInput != "-1": # look out for str "-1" vs int -1
  64.     # do the stuff for this problem
  65.     print(f"I got this input: {myInput}")
  66.     myInput = input()
  67. print(f"I am done! I saw the sentinal value of {myInput}")
  68.  
  69. # multiple quit commands
  70. # Done, done, d, quit
  71. myInput = input()
  72. quitCmds = ["quit", "done", "d", "q"]
  73. while not myInput in quitCmds:
  74.     # do your stuff
  75.     myInput = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement