Advertisement
Guest User

Tempuratures

a guest
Sep 7th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import sys
  2. import math
  3.  
  4. n = int(input()) # the number of temperatures to analyse
  5. closest_temp = 5527
  6. unsign_temp = 0
  7. for i in input().split():
  8. # t: a temperature expressed as an integer ranging from -273 to 5526
  9. t = int(i)
  10.  
  11. if t < 0:
  12. unsign_temp = -t
  13.  
  14. else:
  15. unsign_temp = t
  16. if unsign_temp < closest_temp:
  17. closest_temp = t
  18. print(closest_temp)
  19.  
  20.  
  21.  
  22.  
  23. ##### Goal/objective #####
  24.  
  25. In this exercise, you have to analyze records of temperature to find the closest to zero.
  26.  
  27.  
  28. Sample temperatures
  29. Here, -1 is the closest to 0.
  30. Rules
  31. Write a program that prints the temperature closest to 0 among input data. If two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 and 5, then display 5).
  32. Game Input
  33. Your program must read the data from the standard input and write the result on the standard output.
  34. Input
  35. Line 1: N, the number of temperatures to analyze
  36.  
  37. Line 2: A string with the N temperatures expressed as integers ranging from -273 to 5526
  38.  
  39. Output
  40. Display 0 (zero) if no temperatures are provided. Otherwise, display the temperature closest to 0.
  41. Constraints
  42. 0 ≤ N < 10000
  43. Example
  44. Input
  45. 5
  46. 1 -2 -8 4 5
  47. Output
  48. 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement