Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns
- # input() ALWAYS returns a string
- # myInput = input()
- #
- # # but we might want to change it to something else
- #
- # # input string: "5"... numeric string
- # myInput = int(input()) # float(input())
- #
- # # SPLIT str into a list
- # # Lab 10.6 input: "Pat Silly Doe"
- # # Lab 10.8 input: "apples 5"
- # myList = input().split() # no arg to split means split on any whitespace
- # SPLIT numeric str into a list of ints/floats
- myInput = "31 567 2 93 6" # input()
- strList = myInput.split()
- print(strList) # a list of strings!
- numList = []
- for num in strList:
- numList.append(int(num))
- print(numList)
- # you could do this with a LIST COMPREHENSION
- # [expression for item in other container]
- myInput = "2 34 87 234 99" # input()
- strList = myInput.split()
- numList = [int(num) for num in strList] # "fill the basket" pattern in 1 line!
- print(numList)
- # First (or last) input() call tells you many times to loop
- # Lab 6.17
- # 5
- # 30.0
- # 50.0
- # 10.0
- # 100.0
- # 65.0
- numValues = int(input()) # or even safer... int(input().strip())
- floatValues = []
- for n in range(numValues):
- nextInput = float(input()) # float(input().strip())
- floatValues.append(float(nextInput))
- theMax = max(floatValues)
- for num in floatValues:
- print("{:.2f}".format(num/theMax))
- # LOOPING until we see a SENTINEL VALUE, like "-1"
- # Lab 33.15
- # March 1, 1990
- # April 2 1995
- # 7/15/20
- # December 13, 2003
- # -1
- # # ask for first input
- # myInput = input()
- # # then we can loop...
- # while myInput != "-1":
- # # do our stuff
- #
- # # myInput = input() # last thing... get next input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement