// Subtract discount from price. finalPrice = (numItems * itemPrice) - min(5, numItems) * itemPrice * 0.1;
price = numItems * itemPrice; discount = min(5, numItems) * itemPrice * 0.1; finalPrice = price - discount;
// Filter offensive words. for (String word : words) { ... }
filterOffensiveWords(words);
int width = ...; // Width in pixels.
int widthInPixels = ...;
// Safe since height is always > 0. return width / height;
checkArgument(height > 0); return width / height;
// Compute once because it’s expensive.
// Create a new Foo instance because Foo is not thread-safe.
// Note that order matters because...
@SuppressWarnings("unchecked") // The cast is safe because...
// Get all users. userService.getAllUsers();
// Check if the name is empty. if (name.isEmpty()) { ... }
response = server.Call(request) if response.GetStatus() == RPC.OK: if response.GetAuthorizedUser(): if response.GetEnc() == 'utf-8': if response.GetRows(): vals = [ParseRow(r) for r in response.GetRows()] avg = sum(vals) / len(vals) return avg, vals else: raise EmptyError() else: raise AuthError('unauthorized') else: raise ValueError('wrong encoding') else: raise RpcError(response.GetStatus())
response = server.Call(request) if response.GetStatus() != RPC.OK: raise RpcError(response.GetStatus()) if not response.GetAuthorizedUser(): raise ValueError('wrong encoding') if response.GetEnc() != 'utf-8': raise AuthError('unauthorized') if not response.GetRows(): raise EmptyError() vals = [ParseRow(r) for r in response.GetRows()] avg = sum(vals) / len(vals) return avg, vals