# Webinar Input Patterns Mar 11 2023 # input() ALWAYS returns a string # myInput = input() # that myInput var is definitely a str! # but we might want to change it to something else... # 1 Recast a numeric string into an int or float # 2 Breaking up a long string into a list of smaller strings # 3 Break up a string containing numeric chars into a list of # recast ints or floats # 4 One value tells you how many times to call input() # 5 We DON'T KNOW how many times to call input(), but we know # a sentinel value to stop # 1 Recast a numeric string into an int or float # looks a number... 5 so it's really "5" # myInput = int(input()) # print(type(myInput)) # 2 Breaking up a long string into a list of smaller strings # "Pat Silly Doe" # myInput = "Pat Silly Doe" # input() # strList = myInput.split() # print(strList) # 3 Break up a string containing numeric chars into a list of # recast ints or floats # 10 5 3 21 2 # myInput = "31 333 2 78 92" # input() # strList = myInput.split() # print(strList) # numList = [] # for num in strList: # numList.append(int(num)) # print(numList) # # # 4 One value tells you HOW MANY TIMES to call input() # # ... inputs: # # 5 # # 30.0 # # 50.0 # # 10.0 # # 100.0 # # 65.0 # # numValues = int(input()) # floatList = [] # # for n in range(numValues): # for n in range(0, numValues): # nextInput = float(input()) # floatList.append(nextInput) # print(floatList) # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE # this is a WHILE loop condition # until "-1", or "quit" # ask for the FIRST input() myInput = input() # THEN we can set up a loop condition while myInput != "-1": # as long as the input var doesn't hold the sentinel value, look out for str "-1" vs int -1 # do the stuff for this problem print(f"I got this input: {myInput}") myInput = input() print(f"I am done! I saw the sentinel value of {myInput}")