Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- txt = input('Submission: ') # give user a prompt
- lista = txt.replace(',', ' ').split()
- strt = ""
- flt = 0.0
- intt = 0
- seen_int = False
- kind = None
- for entry in lista:
- if kind is None:
- if entry in ('str', 'float', 'int'):
- kind = entry # what we expect next time
- else: # in case user mistyped
- print(f'Unexpected word: {entry}')
- else: # kind should reference one of str, float or int from previous loop
- if kind == "str":
- strt += entry.strip() # remove leading/trailing spaces
- elif kind == "float":
- flt += float(entry) # place in try/except to catch errors
- elif kind == "int":
- if seen_int:
- intt *= int(entry) # place in try/except to catch errors
- else: # don't want to multiple by 0 for first int
- intt = int(entry) # place in try/except to catch errors
- seen_int = True
- kind = None # ready for next word
- print(intt)
- print(flt)
- print(strt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement