LU11.L02 - Einleser als Modul

'''
input_reader module with input validation
'''
def read_float(text_to_display):
  pass
def read_float(text_to_display):
    while True:
        try:
            num = float(input(text_to_display))
        except ValueError:
            print("Please, enter a real number!")
            continue
        else:
            return num
def read_int(text_to_display):
    while True:
        try:
            num = int(input(text_to_display))
        except ValueError:
            print("Please, enter a valid whole number")
            continue
        else:
            return num

Importieren Sie ihr input_reader Modul in ihrem main.py damit das Programm funktioniert.

# Import the input_reader module here
from input_reader import read_float, read_int
 
def main():
    # do something
    float = read_float('Please enter a real number> ')
    int = read_int('Please enter a whole number> ')
 
    print(float)
    print(int)
 
if __name__ == '__main__':
    main()
  • modul/archiv/m319python/learningunits/lu11/loesungen/einleser.txt
  • Last modified: 2023/11/13 08:56
  • by 127.0.0.1