Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns Feb 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)
- # 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(0, numValues): # [0, 1, 2, 3, 4]
- # 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 we can loop...
- while myInput != "-1": # 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 sentinal value of {myInput}")
- # multiple quit commands
- # Done, done, d, quit
- myInput = input()
- quitCmds = ["quit", "done", "d", "q"]
- while not myInput in quitCmds:
- # do your stuff
- myInput = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement