Advertisement
jspill

webinar-input-patters-2022-08-06

Aug 6th, 2022
1,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. # Webinar Input Patterns
  2.  
  3. # input() ALWAYS returns a string
  4. # myInput = input()
  5. #
  6. # # but we might want to change it to something else
  7. #
  8. # # input string: "5"... numeric string
  9. # myInput = int(input()) # float(input())
  10. #
  11. # # SPLIT str into a list
  12. # # Lab 10.6 input: "Pat Silly Doe"
  13. # # Lab 10.8 input: "apples 5"
  14. # myList = input().split() # no arg to split means split on any whitespace
  15.  
  16. # SPLIT numeric str into a list of ints/floats
  17. myInput = "31 567 2 93 6" # input()
  18. strList = myInput.split()
  19. print(strList) # a list of strings!
  20. numList = []
  21. for num in strList:
  22.     numList.append(int(num))
  23. print(numList)
  24.  
  25. # you could do this with a LIST COMPREHENSION
  26. # [expression for item in other container]
  27. myInput = "2 34 87 234 99" # input()
  28. strList = myInput.split()
  29. numList = [int(num) for num in strList] # "fill the basket" pattern in 1 line!
  30. print(numList)
  31.  
  32. # First (or last) input() call tells you many times to loop
  33. # Lab 6.17
  34. # 5
  35. # 30.0
  36. # 50.0
  37. # 10.0
  38. # 100.0
  39. # 65.0
  40.  
  41. numValues = int(input()) # or even safer... int(input().strip())
  42. floatValues = []
  43. for n in range(numValues):
  44.     nextInput = float(input()) # float(input().strip())
  45.     floatValues.append(float(nextInput))
  46.  
  47. theMax = max(floatValues)
  48. for num in floatValues:
  49.     print("{:.2f}".format(num/theMax))
  50.  
  51.  
  52. # LOOPING until we see a SENTINEL VALUE, like "-1"
  53. # Lab 33.15
  54. # March 1, 1990
  55. # April 2 1995
  56. # 7/15/20
  57. # December 13, 2003
  58. # -1
  59.  
  60. # # ask for first input
  61. # myInput = input()
  62. # # then we can loop...
  63. # while myInput != "-1":
  64. #     # do our stuff
  65. #
  66. #     # myInput = input() # last thing... get next input
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement