Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns 2023 Nov 11
- # 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
- # 5 # that 5 is "5" but I might want the int 5
- # myInput = float(input())# int(input())
- # print(myInput)
- # print(type(myInput).__name__)
- # 2 Breaking up a long string into a list of smaller strings
- # myInput = input()
- # myList = myInput.split()
- # print(myList)
- # 12 28 34 # one input() to be split()
- # 12 # vs 3 separate calls to input()
- # 28
- # 34
- # "Pat Silly Doe" or "Julia Clark"
- # myInput = input().split()
- # # myList = myInput.split()
- # print(myInput)
- # print(len(myInput))
- # 3 Break up a string containing numeric chars into a list of
- # recast ints or floats
- # 12 28 34 # one input() to be split()
- # myInput = input()
- # strList = myInput.split()
- # print(strList) # ['12', '99', '34', '25']
- #
- # numList = []
- # for item in strList:
- # numList.append(int(item))
- # print(numList) # [12, 99, 34, 25]
- # 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
- # numVals = int(input())
- # floatList = []
- #
- # # loop with range()
- # for num in range(numVals):
- # nextInput = float(input())
- # floatList.append(nextInput)
- # # floatList.append(float(input()))
- #
- # 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
- # myInput = input()
- # set up a while loop
- # while myInput != "-1":
- # # do whatever we need to do
- # print(myInput)
- # # get next input
- # myInput = input()
- # print("OK. Quitting...")
- # # Stop on quit or done or d
- quitCmds = ["quit", "done", "d"]
- myInput = input()
- while not myInput in quitCmds:
- # do stuff
- print(f"I got the command {myInput}")
- myInput = input()
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement