Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

python - I want to know how to correct this error - TypeError: argument 2 to map() must support iteration at line 55 of my code? thank you

#!/bin/python

import math
import os
import random
import re
import sys

#
# Complete the 'count_pebbles' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts the following parameters:
#  1. INTEGER k
#  2. INTEGER d
#  3. INTEGER_ARRAY queries
#

def count_pebbles(k, d, queries):
    # Count the total number of pebbles accumulated after the number of days indicated by each query
     #store all results for each day
    store = []
    #stores for pebble count and inc
    TL, GL = 0, 0
    curr = k
    
    #similar to above approach, but stores the values instead of improptu print
    for i in range(1,max(queries)+1):
        TL+=curr
        curr+=k
        if(i == d):
            TL -= k*d
            GL += k*d
        store.append([TL, GL])
    
    #for each query, get value from store
    for query in queries:
        return store[query-1][0]

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    first_multiple_input = raw_input().rstrip().split()

    k = int(first_multiple_input[0])

    d = int(first_multiple_input[1])

    q = int(first_multiple_input[2])

    queries = map(int, raw_input().rstrip().split())

    result = count_pebbles(k, d, queries)

    fptr.write('
'.join(map(str, result)))
    fptr.write('
')

    fptr.close()

question from:https://stackoverflow.com/questions/65890312/i-want-to-know-how-to-correct-this-error-typeerror-argument-2-to-map-must-s

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...