Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns Nov 12 2022
- # input() ALWAYS returns a string
- # myInput = input()
- #
- # but we might want to change it to something else...
- # 1 Turn 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 Turn a numeric string into an int or float
- # myInput = input()
- # myInput = "5" # input()
- # myInput = int(input()) # float(input())... int(input().strip())
- # 2 Breaking up a long string into a list of smaller strings
- # myInput = input()
- # myInput = "Pat Silly Doe"
- # strList = myInput.split()
- # print(strList)
- # 3 Break up a string containing numeric chars into a list of
- # recast ints or floats
- # Lab 28.11... 10 5 3 21 2
- # myInput = "31 333 2 78 92"
- # strList = myInput.split()
- # print(strList)
- # numList = []
- # for num in strList:
- # numList.append(int(num))
- #
- #
- # # You could do this as a LIST COMPREHENSION
- # # [expression for item in other container]
- # numList = [int(num) for num in strList]
- # print(numList)
- #4 One value tells you HOW MANY TIMES to call input()
- # like Lab 6.17
- # ... inputs:
- # 5
- # 30.0
- # 50.0
- # 10.0
- # 100.0
- # 65.0
- # numValues = int(input())
- # numValues = 5
- # floatValues = []
- #
- # for n in range(numValues): # [0, 1, 2, 3, 4]
- # nextInput = float(input())
- # floatValues.append(nextInput)
- # print(floatValues)
- # 5 We DON'T KNOW how many times to call input(), but we know to stop on some SENTINEL VALUE
- # Lab 33.15
- # March 1, 1990
- # April 2 1995
- # 7/15/20
- # December 13, 2003
- # -1
- # ask for the FIRST input()
- myInput = input()
- # THEN we can loop...
- while myInput != "-1": # not the int -1 but the str "-1"... our loop will not ever stop if we're testing the wrong one!!!
- # do our stuff
- myInput = input() # last in loop, grab input for next iteration
- # multiple quit commands
- # Done, done, d, quit
- # while myInput != "Done" and myInput != "done" and myInput != "d":
- quitCommands = ["Done", "done", "d", "quit"]
- while not myInput in quitCommands:
- # do your stuff
- myInput = input()
Advertisement
Add Comment
Please, Sign In to add comment