Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns June 10 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()
- # myInput = input().split()
- print(strList)
- # getting a series of numbers... 12 44 67 23
- # 3 Break up a string containing numeric chars into a list of
- # recast ints or floats
- myInput = "31 333 2 78 92" # input()
- strList = myInput.split()
- print(strList)
- numList = []
- # for __ in __someContainer__
- for num in strList:
- numList.append(int(num))
- print(numList)
- # 4 One value tells you HOW MANY TIMES to call input()
- # 5 # so 5 more pieces of data coming in...
- # 30.0
- # 50.0
- # 10.0
- # 100.0
- # 65.0
- # numVals = int(input()) # get that first input
- # floatList = []
- #
- # for num in range(numVals):
- # # get each next input, do your stuff
- # 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
- # ask for the FIRST input()
- # myInput = input()
- # # THEN I can set up a while loop condition...
- # while myInput != "-1": # pay attention to string vs int
- # print(f"I got this input: {myInput}")
- # myInput = input()
- # print(f"I am done! I saw the sentinel value of {myInput}")
- # Condition is never satisfied... comparing ints and strings
- # myInput = int(input())
- # while myInput != "-1":
- # print(myInput * 2)
- # myInput = int(input())
- # print(f"I am done! I saw the sentinel value of {myInput}")
- # multiple quit commands
- # You can quit with "quit" or "done" or "d"
- myInput = input()
- quitCommands = ["quit", "done", "d"] # pro tip: put them in a list!
- while not myInput in quitCommands:
- print(f"I received the command: {myInput}")
- myInput = input()
- print("OK. Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement