Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns 2024 Feb 10
- # input() ALWAYS returns a string
- # Some common patterns...
- # 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
- # 3 # not the int 3 it's "3"
- # myInput = int(input())
- # # myInput = int(myInput)
- # print(type(myInput).__name__)
- # 2 Breaking up a long string into a list of smaller strings
- # "Pat Silly Doe" or "Julia Clark"
- # myInput = input().split()
- # print(myInput)
- # strList = myInput.split()
- # print(strList)
- # 3 Break up a string containing numeric chars into a list of
- # recast ints or floats
- # 24 88 32
- # myInput = input().split()
- # print(myInput)
- #
- # # fill the basket
- # numList = []
- # for num in myInput:
- # numList.append(int(num))
- # print(numList)
- # 4 One value tells you HOW MANY TIMES to call input()
- # Any "known number of times" means a for loop
- # 5
- # 30.0
- # 50.0
- # 10.0
- # 100.0
- # 65.0
- # call input() to get the number of times
- # numTimes = int(input())
- # floatList = []
- #
- # # loop over that range() to get the next inputs
- # for n in range(numTimes):
- # 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
- # get the first input()
- myInput = input()
- # set up a while loop using that var in its condition
- # while myInput != "quit":
- # while myInput != -1:
- # # do your stuff
- #
- # myInput = input()
- # Use a list for multiple sentinel values
- # Stop on quit, or done, or d
- myInput = input()
- quitCommands = ["quit", "done", "d"]
- while not myInput in quitCommands: # this saves you from having more complex Boolean conditions
- # do your stuff
- myInput = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement