Advertisement
jspill

webinar-input-patterns-2023-03-11

Mar 11th, 2023
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. # Webinar Input Patterns Mar 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. # 1 Recast a numeric string into an int or float
  17. # looks a number...  5 so it's really "5"
  18. # myInput = int(input())
  19. # print(type(myInput))
  20.  
  21. # 2 Breaking up a long string into a list of smaller strings
  22. # "Pat Silly Doe"
  23. # myInput = "Pat Silly Doe" # input()
  24. # strList = myInput.split()
  25. # print(strList)
  26.  
  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. # # 4 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(numValues): # for n in range(0, numValues):
  52. #     nextInput = float(input())
  53. #     floatList.append(nextInput)
  54. # print(floatList)
  55.  
  56. # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE
  57. # this is a WHILE loop condition
  58. # until "-1", or "quit"
  59.  
  60. # ask for the FIRST input()
  61. myInput = input()
  62. # THEN we can set up a loop condition
  63. while myInput != "-1": # as long as the input var doesn't hold the sentinel value, 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 sentinel value of {myInput}")
  68.  
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement