deomorxsy

Untitled

Sep 22nd, 2020 (edited)
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. '''
  4. Sum of Consecutive Odd Numbers II
  5.  
  6. Read an integer N that is the number of test cases. Each test case is a line containing two
  7. integer numbers X and Y. Print the sum of all odd values between them, not including X and Y.
  8. Input: The first line of input is an integer N that is the number of test cases that follow.
  9. Each test case is a line containing two integer X and Y.
  10. Output: Print the sum of all odd numbers between X and Y.
  11. '''
  12.  
  13. numero_testes = int(input()); #para o for loop
  14. casos = []
  15. acumulador = []
  16.  
  17. somatorio = 0
  18.  
  19. for i in range(numero_testes):
  20.     casos = [int(i) for i in input().split(' ')]
  21.     somatorio=0
  22.    
  23.     while ((casos[0] == casos[1])
  24.         or (casos[0] + 1 == casos[1])
  25.         or (casos[1] + 1 == casos[0])
  26.         or (casos[0] == casos[1] + 2 and (casos[1]-1) % 2 == 0)
  27.         or (casos[1] == casos[0] + 2 and (casos[0]-1) % 2 == 0)):
  28.  
  29.         somatorio = 0
  30.         print("N1 Loop")
  31.         print("somatorio={}".format(somatorio))
  32.         print("somatorio depois da soma={}\n".format(somatorio))
  33.         acumulador.append(somatorio)
  34.         break
  35.     '''
  36.     somatorio = 0
  37.     while (casos[0] + 1 == casos[1]) or (casos[1] + 1 == casos[0]):
  38.         somatorio = 0
  39.         print("N2 Loop")
  40.         print("somatorio={}".format(somatorio))
  41.         print("somatorio depois da soma={}\n".format(somatorio))
  42.         acumulador.append(somatorio)
  43.         break
  44.     '''
  45.     somatorio = 0
  46.     while (casos[0] < casos[1]):
  47.         for i in range(casos[0],casos[1]):
  48.             while (i % 2 != 0) and (i != casos[0]): #if
  49.                 print("N2 Loop")
  50.                 print("somatorio={}".format(somatorio))
  51.                 somatorio += i;
  52.                 print("somatorio depois da soma={}\n".format(somatorio));
  53.                 #print("{}".format(casos[i]))#DEBUGGER
  54.                 #acumulador[len(acumulador)-1] = somatorio
  55.                 acumulador.append(somatorio)
  56.                 break
  57.         break
  58.  
  59.    
  60.     somatorio=0
  61.     while (casos[0] > casos[1]):
  62.         for i in range(casos[0],casos[1],-1): #start,stop,step
  63.             while (i % 2 != 0) and (i != casos[0]): #if
  64.                 print("N3 Loop")
  65.                 print("somatorio={}".format(somatorio))
  66.                 somatorio += i
  67.                 print("somatorio depois da soma={}\n".format(somatorio))
  68.                 acumulador.append(somatorio)
  69.                 break
  70.             #print("{}".format(i))#DEBUGGER
  71.         #print("casos[0] não é maior que caso[1].") #DEBUGGER
  72.         break
  73.  
  74.    
  75. for i in range(len(acumulador)-1):
  76.     while i == len(acumulador)-1:
  77.         acumulador[i] = somatorio
  78.  
  79. print("=====================")
  80. for i in range(len(acumulador)):
  81.     print("{}".format(acumulador[i]))
  82.  
  83.  
  84. '''
  85.     if (casos[0] < casos[1]):
  86.         for i in range(len(casos)):
  87.             print("{}".format(casos[i]))
  88.     else:
  89.         print("casos[0] não é maior que caso[1].")
  90.  
  91. #for item in range(casos[i][0],casos[i][1],-1):
  92. '''
  93. '''
  94. index=0
  95. while (index <= numero_testes):
  96.     casos = input().split('')
  97.     index+=1
  98.  
  99. '''
Add Comment
Please, Sign In to add comment