• Register
1 vote
696 views

Problem:

I have a thousand line codes of python that I can not attach here. I am attaching the infected part from my whole code. This portion of code is producing the error. can only concatenate tuple (not "int") to tuple

def calculateAns(num1, num2, ans, right):
    if ans == num1+num2:
        print 'Right'
        right = right + 1
    else:
        print 'Wrong'
    return right, ans

I am looking forward to you guys to have a legit solution.

Thanks.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

The function calculatekAns() returns a tuple in your program as you have put a comma between right and ans inside the return function that contains two values. It might be confusing but, yeah parenthesis is optional (in most of the cases) but the comma makes it a tuple type. So, can assign the value of return inside the right

right = calculatekAns(num1, num2, ans, right)

And now you can return the value of right only in your program, and that should work fine.

def calculateAns(num1, num2, ans, right):
    if ans == num1+num2:
        print 'Right'
        right = right + 1
    else:
        print 'Wrong'
    return right

Leave a kudos if it helps you. Thanks.

13 9 6
94,240 points

Related questions

0 votes
1 answer 21 views
21 views
Problem: I am providing two values (mon_voltage and core_voltage) via the command line and I need to find a "starting point" from a two dimensional array where my iteration or loop will start from. Here is my code: myArray = [[1.02,1.13],[1.02,1.16],[1.02,1. ... : can only concatenate tuple (not "int") to tuple I can't figure out why start_point, which is an index, is a tuple. Please help.
asked Feb 13 sasha 13.2k points
1 vote
1 answer 1.1K views
1.1K views
Problem: I made a tuple to add to my main program . But this thing does not seem to work . I wrote this code: print("You should study hard to pass the exam") exam=("Study","Pc","python") print ("The things I have :") for stuff in exam: print (stuff) ... <module> exam += extra TypeError: can only concatenate tuple (not "str") to tuple Can anyone sort out this problem and help me out to solve this?
asked Apr 21, 2020 samhaz 5k points
0 votes
1 answer 110 views
0 votes
1 answer 209 views
1 vote
2 answers 918 views
918 views
Problem: I have a very simple question for you guys. What does the error: can only concatenate list (not "int") to list mean? Well, let me clarify my problem a little bit more. I am trying to add to lists in python, but it&rsquo;s not working. Yeah, I am a new ... my snippet number=[1, 2, 3] number[1:]+number[0] Where did I wrong in my program? Your kind solution is much appreciated. Thanks mate!
asked Mar 30, 2020 Gavin 15.3k points
0 votes
1 answer 24 views
24 views
Problem: I am new to the world of programming . I recently started learning Python. I wrote following program: def check(list): for i in range(len(list)): list[i] = list[i+1] value = list[i] print(value) input_list = eval(input("Enter the items of list")) check( ... to replace the first item of the list with the second, and so on. I have no idea why this error is occurring. Can anybody help me?
asked Dec 27, 2020 Code Learner 6.2k points
0 votes
1 answer 47 views
47 views
Problem: sort method What method can be used to convert a list to a tuple? The sort method rearranges the elements of a list so they appear in ascending or descending order.
asked Nov 6, 2020 Mashhoodch 9.9k points
0 votes
1 answer 129 views
129 views
Problem: Hello kodlogs, I am new in this python language switched from the c language I want to know that how can we convert the list to a tuple we can achieve this by the list by the tuple(), but is this a typecast like we were doing in the string to an integer?
asked Jun 14, 2020 Gavin 15.3k points
0 votes
1 answer 62 views
62 views
Problem: Hello kodlogs, I am new in this python language switched from the c language I want to know that how can we convert the tuple to a list we can achieve this by the list by list() , but is this a typecast like we were doing in the string to an integer?
asked Jun 8, 2020 Gavin 15.3k points
0 votes
1 answer 13 views
13 views
Problem: The code is the following (I am new to Python/Mysql): import mysql.connector conn = mysql.connector.connect(host='localhost',user='user1',password='puser1',db='mm') cursor = conn.cursor() string1 = 'test1' insert_query = """INSERT INTO items_basic_info (item_name) VALUES (%s)""", (string1) cursor.execute(insert_query) conn.commit() When I run this code I get this error:
asked Feb 21 Mashhoodch 9.9k points