Advertisement
srslyyou

Untitled

Nov 29th, 2017
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1. #We provide you with a number N.
  2.  
  3. #Create a list then, using a loop, populate the list with N elements. Set each list element to the index multiplied by 10.
  4.  
  5. #Beware: we might pass in a value 0, in which case you should return an empty list.
  6.  
  7. # Get N from the command line
  8. import sys
  9. N= int(sys.argv[1])
  10.  
  11. # Your code goes here
  12. #create a list
  13.  
  14. my_list = []
  15. my_newlist =[]
  16. if N <= 0:
  17.     print(my_list)
  18.    
  19. else:
  20.     for x in range(N):  
  21.         my_list.append(x)  
  22.         my_newlist= [i* 10 for i in my_list] # not getting the statement 'i * 10 for in i' statement
  23.     print(my_newlist)
  24.  
  25. ##############
  26. We are passing in 3 inputs.
  27.  
  28. a list of numbers
  29. a multiplier value, M
  30. a value, N
  31. You should multiply every Nth element (do not multiply the 0th element) by M. So, if N is 3, you start with the 3rd element, which is index 2.
  32.  
  33. If there are less than N elements then you should output the unchanged input list.
  34. ################
  35.  
  36. # Get our input from the command line
  37. import sys
  38. M= int(sys.argv[2])
  39. N= int(sys.argv[3])
  40.  
  41. # convert strings to integers
  42. numbers= sys.argv[1].split(',')
  43. for i in range(0, len(numbers)):
  44.   numbers[i]= int(numbers[i])
  45.  
  46.  
  47. numbers[N-1::N] = [x * M for x in numbers[N-1::N]]  # I have no clue what kind of wizardry this is. but it looks nice and it works
  48. print(numbers)
  49.  
  50.  
  51. #################
  52.  
  53. # Get our list from the command line arguments
  54. import sys
  55. numbers= sys.argv[1:]
  56.  
  57. # Convert the command line arguments into 2d list
  58. for i in range(0,len(numbers)):
  59.   numbers[i]= numbers[i].split(',')
  60.  
  61. total=0
  62. for row in numbers:
  63.     subTotal = sum([int(col) for col in row]) #I don't get the brackets, and again for numbers for numbers in row - doesn't make sense # to me
  64.     print(subTotal)
  65.     total += subTotal
  66. print(total)
  67.  
  68. '''  The below are all failures - one of the only I kept
  69. total=0
  70. tTotal=0
  71. for row in range (len(numbers)):
  72.    for col in range(len(numbers[0])):
  73.        total += int(numbers[row][col])
  74.    tTotal += total
  75.    print(total)
  76. print(tTotal)
  77.  
  78.  
  79. # Get our list from the command line arguments
  80. import sys
  81. numbers= sys.argv[1:]
  82.  
  83. # Convert the command line arguments into 2d list
  84. for i in range(0,len(numbers)):
  85.  numbers[i]= numbers[i].split(',')
  86.  
  87. total=0
  88. for row in numbers:
  89.    subTotal = sum([int(col) for col in row])
  90.    print(subTotal)
  91.    total += subTotal
  92. print(total)
  93.  
  94.  
  95. total=0
  96. tTotal=0
  97. for row in range (len(numbers)):
  98.    for col in range(len(numbers[0])):
  99.        total += int(numbers[row][col])
  100.    tTotal += total
  101.    print(total)
  102. print(tTotal)
  103. '''
  104.  
  105.  
  106. #########################
  107.  
  108. # Get our arguments from the command line
  109. import sys
  110. A= int(sys.argv[1])
  111. B= int(sys.argv[2])
  112.  
  113. # Your code goes here
  114.  
  115. #Create a row of columns
  116. newList=[]
  117.  
  118.  
  119. for x in range(0, A): # this says this many times in variable A do
  120.   newList.append([]) # appends a new list x amount of times
  121.  
  122.   for y in range(0, B): # this says as many times in B
  123.     newList[x].append('R' + str(x) + 'C' + str(y)) #
  124.  
  125. print(newList) #this only prints once because it's not indented
  126.  
  127. # So for the input of 2,3  it creates two lists and then while in the  
  128. # for y statement it says n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement