Advertisement
DacCum

py lab 1

Feb 2nd, 2022 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. #py lab 1
  2. #1
  3. print("Сonditions: a, b = (1..100)")
  4. a = int(input("Enter a: "))
  5. b = int(input("Enter b: "))
  6. while (a < 1 or a > 100 or b < 1 or b > 100):
  7.   print("ERROR: invalid values")
  8.   print("Enter a, b again")
  9.   a = int(input("Enter a: "))
  10.   b = int(input("Enter b: "))
  11. if a > b:
  12.   x = a / b + 1
  13. elif a == b:
  14.   x = -2
  15. else:
  16.   x = (a - b) / b
  17. print("Result: {0}".format(x))
  18.  
  19. #2
  20. N = 30
  21. sum = 0
  22. for i in range(N):
  23.   sum += 1 / (i+1)
  24. print("Result: {0}".format(sum))
  25.  
  26. #3
  27. N = int(input("Enter N: "))
  28. for i in range(N):
  29.   print(i * 2 * ' ', end='')
  30.   for j in range(i, N):
  31.     print(j + 1, end=' ')
  32.   print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement