Advertisement
timber101

LBOA_wk1_Procedure/Functions

Apr 24th, 2022
1,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. # LBOA - Page 7 - 9?
  2. # PDF Link https://drive.google.com/drive/folders/1XKpl6FsoNK-I94P-_Es6QlQp1otNx4WD
  3.  
  4. #  create a program that takes 2 numbers and returns the largest
  5. """
  6. num1 = int(input("Please enter first number >>")) # 4 data types, string, integer (whole number 1, 99 -3) floats (decimal)
  7.                                                    # Boolean (yes or no), True or False, 1 or 0
  8. num2 = int(input("Please enter second number >>"))
  9.  
  10. if num1 > num2:
  11.    highest = num1
  12. else:
  13.    highest = num2
  14.  
  15. print("The highest number is " + str(highest)) # cast highest into a string, + contenation (join)
  16. print("The highest number is (second print statement) ", highest)
  17. """
  18. """
  19. # as a procedure - sub program - function
  20.  
  21. def higher_number(noz1, noz2): # parameters used only within the procedure/function
  22.    if noz1 > noz2:
  23.        highest = noz1
  24.    else:
  25.        highest = noz2
  26.    
  27.    print("The highest number is (second print statement) ", highest)
  28.    
  29. # to use the procedure, we have to call it.
  30.  
  31. num1 = int(input("Please enter first number >>")) # 4 data types, string, integer (whole number 1, 99 -3) floats (decimal)
  32.                                                    # Boolean (yes or no), True or False, 1 or 0
  33. num2 = int(input("Please enter second number >>"))
  34.  
  35. higher_number(num1, num2) # arguments
  36. """  
  37. # as a function
  38. def higher_number_function(noz1, noz2): # parameters used only within the procedure/function
  39.     if noz1 > noz2:
  40.         highest = noz1
  41.         # return noz1
  42.     else:
  43.         highest = noz2
  44.         # return noz2
  45.    
  46.     return highest
  47.    
  48. # to use the function, we have to call it.
  49.  
  50. num1 = int(input("Please enter first number >>")) # 4 data types, string, integer (whole number 1, 99 -3) floats (decimal)
  51.                                                     # Boolean (yes or no), True or False, 1 or 0
  52. num2 = int(input("Please enter second number >>"))
  53.  
  54. highest_num = higher_number_function(num1, num2) # arguments
  55.  
  56. print("The highest number of", num1 , "and", num2, "is", highest_num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement