Python-nmap network scanner does not allow input of ip range, only specific IP addresses


# run with sudo Python3

# pip3 install python-nmap
import nmap

scanner = nmap.PortScanner()

print("Welcome, this is a simple nmap automation tool")
print("Currently installed nmap version: ", scanner.nmap_version())

ip_addr = ''  # default ip address
prompt_str = "Please enter the IP address you want to scan ("+ip_addr+"): "
ip_addr = input(prompt_str) or ip_addr
print("Selected IP: ", ip_addr)

resp = input("""nEnter the scan type you want to run
                1) SYN ACK Scan
                2) UDP Scan
                3) Comprehensive Scan n""")
print("You have selected option: ", resp)

def run_scan(args: str, port_range: str = '1-1024'):
    scanner.scan(ip_addr, port_range, args)
    print("Ip Status: ", scanner(ip_addr).state())
    protocols = scanner(ip_addr).all_protocols()
    for protocol in protocols:
        print("("+protocol+") open ports: ", scanner(ip_addr)(protocol).keys())

# -v verbose
if resp == '1':
    # -sS TCP SYN scan
    run_scan('-v -sS')
elif resp == '2':
    # -sU UDP SYN scan
    run_scan('-v -sU')
elif resp == '3':
    # -sS TCP SYN scan
    # -sV Version detection
    # -sC script scan using the default set of scripts
    # -A Aggressive scan options
    # -O Enable OS detection
    run_scan('-v -sS -sV -sC -A -O')
    print("Please enter a valid option")

For instance, when I try entering it outputs:

{'udp': {'method': 'udp', 'services': '1-1024'}}
Traceback (most recent call last):
  File "", line 37, in <module>
    print("IP Status: ", scanner(ip_address).state())
  File "/usr/local/lib/python3.8/dist-packages/nmap/", line 568, in __getitem__
    return self._scan_result('scan')(host)
KeyError: ''

But entering a single address works fine.

How do I allow it to take in ranges?