Q:

change (lack of) user input to default string value

This is probably a straight forward question but I don't have the Python fundamentals down yet (running before walking)
I want user inputs for the following (coordinate) variables:
source_x = input('enter blast x: ')
source_y = input('enter blast y: ')
source_z = input('enter blast z: ')
receiver_x = input('enter receiver x: ')
receiver_y = input('enter receiver y: ')
receiver_z = input('enter receiver z: ')

When the user input is Enter for the z coordinate (or any other), the following error arises:
    source_z = float(source_z)
ValueError: could not convert string to float: ''

I understand the error, the Enter input was seen as a string, but is there a quick way to identify and convert the Enter input to (e.g.) a 0?
Just in case I want to undertake bulk imports and not stop my calculations further down the code.
kind regards

A:

The solution is to check the input value to see if it is composed of digits and then cast it to the desired type or assign a default value else:
import re

is_number = re.compile(r'^[-+]?[0-9]*\.?[0-9]+$')

src_x = input('enter blast x: ')
src_y = input('enter blast y: ')
src_z = input('enter blast z: ')

rcv_x = input('enter receiver x: ')
rcv_y = input('enter receiver y: ')
rcv_z = input('enter receiver z: ')

src_x = float(src_x) if is_number.match(src_x) else 0
src_y = float(src_y) if is_number.match(src_y) else 0
src_z = float(src_z) if is_number.match(src_z) else 0

rcv_x = float(rcv_x) if is_number.match(rcv_x) else 0
rcv_y = float(rcv_y) if is_number.match(rcv_y) else 0
rcv_z = float(rcv_z) if is_number.match(rcv_z) else 0

