November 2018
Intermediate to advanced
446 pages
12h 11m
English
We will be using the split() method for Python strings to extract elements that are separated by a specific character in a string. Therefore, we will require all data coming from clients to be formatted this way (integers separated by commas), and, if a client sends in something that is not in this format, we will simply send back an error message and require them to make a new message.
The basic calculation logic is included in the Chapter18/example2.py file, as follows:
# Chapter18/example2.pyfrom operator import mulfrom functools import reducetry: while True: line = input('Please enter a list of integer, separated by commas: ') try: nums = list(map(int, line.split(','))) except ValueError: print('ERROR. ...Read now
Unlock full access