replace a value in a list according to the user desire which has a relation with another list

count=0
x='yes'
name=['thilini','umanda','dilki']
result=[20,40,22]
dct=dict((a,b)for a,b in zip(name,result))
golf_no=int(input('how many golfers are there in the group?'))
while golf_no>count:
    count=count+1
    print('enter the name and the result')
    name_new=str(input('enter the name'))
    result_new=int(input('enter the result'))
    if name_new in name:
        print('this name is already exists')
        answer=str(input('are you sure that you want to replace?'))
        if answer==x:

            print('data is altered')
        else:
            print('try again')
    else:
        name.append(name_new)
        result.append(result_new)
        print('your data entry was successful')
print(name)        
print(result)

1 answer

  • answered 2018-04-17 04:20 bingi

    You can find the index of the name by index method. then replace the result value of that index. please let me know if you need any help..