Advertisement
SimeonTs

SUPyF Functions - Extra 7. Greater of Two Values

Jun 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. """
  2. Functions and Debugging
  3. Проверка: https://judge.softuni.bg/Contests/Compete/Index/922#6
  4.  
  5. 07. Greater of Two Values
  6.  
  7. Условие:
  8. You are given two values of the same type as input. The values can be of type int, char of string.
  9. Create a function that returns the greater of the two values:
  10.  
  11. Examples
  12. Input:
  13. int
  14. 2
  15. 16
  16. Output:
  17. 16
  18.  
  19. Input:
  20. char
  21. a
  22. z
  23. Output:
  24. Z
  25.  
  26. Input:
  27. string
  28. Ivan
  29. Todor
  30. Output:
  31. Todor
  32.  
  33. Hints
  34. 1.  For this function you need to create three functions with the same name and different signatures
  35. 2.  Create a function which will compare integers.
  36. 3.  Lastly you need to create a function to compare the other types.
  37. 4.  The last step is to read the input, use appropriate variables and call the function you’ve just written.
  38. """
  39.  
  40. type_value = input()
  41. value1 = input()
  42. value2 = input()
  43.  
  44.  
  45. def int_values():
  46.     if int(value1) > int(value2):
  47.         print(value1)
  48.     else:
  49.         print(value2)
  50.  
  51.  
  52. def char_values():
  53.     if ord(value1) > ord(value2):
  54.         print(f"{value1}")
  55.     else:
  56.         print(f"{value2}")
  57.  
  58.  
  59. def str_values():
  60.     if value1 > value2:
  61.         print(value1)
  62.     else:
  63.         print(value2)
  64.  
  65.  
  66. def checker():
  67.     if type_value == "int":
  68.         int_values()
  69.     elif type_value == "char":
  70.         char_values()
  71.     elif type_value == "string":
  72.         str_values()
  73.  
  74.  
  75. checker()type_value = input()
  76. value1 = input()
  77. value2 = input()
  78.  
  79.  
  80. def int_values():
  81.     if int(value1) > int(value2):
  82.         print(value1)
  83.     else:
  84.         print(value2)
  85.  
  86.  
  87. def char_values():
  88.     if ord(value1) > ord(value2):
  89.         print(f"{value1}")
  90.     else:
  91.         print(f"{value2}")
  92.  
  93.  
  94. def str_values():
  95.     if value1 > value2:
  96.         print(value1)
  97.     else:
  98.         print(value2)
  99.  
  100.  
  101. def checker():
  102.     if type_value == "int":
  103.         int_values()
  104.     elif type_value == "char":
  105.         char_values()
  106.     elif type_value == "string":
  107.         str_values()
  108.  
  109.  
  110. checker()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement