Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar Input Patterns July 15 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 like a number... 5 but it's really the string "5"
- # easy, recast
- # myInput = int(input()) # or float(input()) if you want a float
- # 2 Breaking up a long string into a list of smaller strings
- # "Pat Silly Doe"
- # myInput = input()
- # strList = myInput.split()
- # strList = input().split() # could do it one step
- # print(strList)
- # getting a series of numbers...
- # 12 44 67 23
- # myInput = "12 44 67 23" # input()
- # strList = myInput.split()
- # print(strList)
- # # traditional for loop for new list
- # numList = []
- # for num in strList:
- # numList.append(int(num))
- # # or list comprehension for new list
- # numList = [int(num) for num in strList]
- # 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())
- # floatList = [] # fill this basket...
- #
- # for num in range(numVals): # do this 5 times
- # # get each next input, do your stuff
- # nextInput = float(input())
- # floatList.append(nextInput)
- # print(floatList)
- #
- # Question on "printing a list without brackets"... which isn't necessarily something you need to do
- # for n in floatList:
- # print(n, end=" ")
- # print() # get the line return back, unless a question says otherwise
- #
- # # " ".join(listOfStrings)
- # print(" ".join([str(num) for num in floatList]))
- # Question on range(len())
- # myList = ["Scooby", "Shaggy", "Velma", "Daphne", "Fred", "Scrappy"]
- # for item in myList:
- # print(item)
- #
- # for n in range(len(myList)):
- # print(n)
- # print(myList[n])
- # back to Input Patterns...
- # 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 set up a WHILE LOOP
- # while myInput != "-1": # or whatever value tells you to stop
- # # do what you need with that input...
- #
- # # get the next input
- # myInput = input()
- # multiple quit commands
- # myInput = input()
- # quitCommands = ["quit", "done", "d"] # put them in a list to avoid many conditions joined by an OR
- # while not myInput in quitCommands:
- # print(f"I got the command: {myInput}")
- # myInput = input()
- # print("OK. Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement