Title | My programming Assignment Unit 6 |
---|---|
Course | Programming Fundamentals |
Institution | University of the People |
Pages | 5 |
File Size | 286.7 KB |
File Type | |
Total Downloads | 77 |
Total Views | 149 |
Download My programming Assignment Unit 6 PDF
My bool.py Script screenshot
My bool.py Output screenshot
Script code used in developing the program # the function works as a number validator. It turns the input in a float # value can't be possible, new input is claimed def validate_number(number): while True: try: number = float(number) return number break except: number = input("Invalid input. ReEnter the number: ") True
# Here compares the 2 input numbers and returns # 1 if a > b # 0 if a == b # -1 if a < b def compare(a, b): if a > b: return " 1" elif a == b: return " 0" return "-1"
# the user must be prompted for the values of a and b. reading number1 valA = input("Enter the 1st number: ") # calling the validate_number fucntion validate_number(valA)
# the user must be prompted for the values of a and b. reading number2 valB = input("Enter the 2nd number: ") # calling the validate_number fucntion validate_number(valB)
print("\n") print("\nTesting the comparations...")
# testing the compare function for each condition print(compare(5, 2)) # a > b print(compare(2, 5)) # a < b print(compare(3, 3)) # a == b
print("\n") # calling & printing the result of the compare function print("The comparation's result between the numbers is:") print(compare(valA, valB))...