LU10.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/m319/learningunits/lu10/loesungen/einleser.txt
  • Zuletzt geändert: 2024/03/28 14:07
  • von 127.0.0.1