[Solved] Python: getting info from file? [closed]

Open your file, iterate over its lines with a for loop, split each line by commas and print second field. This should work: filepath = raw_input(‘Input file path:\n’) with open(filepath) as f: for line in f: print line.split(‘,’)[1] 2 solved Python: getting info from file? [closed]

[Solved] Python and SQlite [closed]

data = conn.execute(“SELECT cost from test where name like ‘fish'”).fetchall() Also, chances are, you don’t need to use a cursor for whatever you are doing. solved Python and SQlite [closed]

[Solved] Python bank game won’t go back up [closed]

A while loop that checks whether the value of account is zero would be a way to quit: while account != 0: Floating point zero is not always precisely zero: >>> 27.33 – 25.0 – 2.33 -1.7763568394002505e-15 If account is a float variable, you have to make allowances for this: while abs(account) < 0.000000001: 2 … Read more

[Solved] Finding neighbours of an element in a matrix? [closed]

# 2dMatrix: Your matrix # x: x-coordinate of the element for which you’re searching for neighbors # y: y-coordinate of the element for which you’re searching for neighbors def nearest_elements_2dMatrix(2dMatrix, x,y): upleft = 2dMatrix[x-1][y-1] if (x-1 >= 0 and y-1>=0) else None downleft = 2dMatrix[x-1][y+1] if (x-1 >= 0 and y+1 < len(2dMatrix)) else None … Read more

[Solved] Python script: Syntax error

You are missing parenthesis around the print statements. The correct syntax is: print(“Temperature: “, temperature,” C humidity: “, humidity) Python 3 requires print statements containing text to be inside of (” “), variables inserted like: print(” text “, variable, “more text”) solved Python script: Syntax error

[Solved] Recursive Binary search algorithm – Python [closed]

Your existing function has at least two major problems: It doesn’t return the value from the recursive calls, meaning that it usually ends up returning None if it finishes; it uses the wrong bounds to slice the list, meaning half the time it ends up with infinite recursion. If you fix those, then all you … Read more

[Solved] Python: sqlite3 [closed]

This is what the first parameter of the connect function is for: import sqlite3 db = sqlite3.connect(“C:/temp/MyLittleDatabase”) db.execute(“CREATE TABLE IF NOT EXISTS T(x)”) db.execute(“INSERT INTO T VALUES (42)”) cursor = db.execute(“SELECT x FROM T”) for row in cursor: print row[0] 4 solved Python: sqlite3 [closed]

[Solved] please correct the following code [closed]

in your count() function, the variable probability is created when the function called, it is not the same variable probability you declared at beginning. I think you may want to use the variable as global variable. 2 solved please correct the following code [closed]

[Solved] create random questions using a txt file

Try storing your data in a standard structured format such as JSON. A library for parsing JSON is included with Python. Create a file called questions.json containing: { “What are your plans for today?”: { “answers”: [“nothing”, “something”, “do not know”], “correct_answer”: 2 }, “how are you?”: { “answers”: [“well”, “badly”, “do not know”], “correct_answer”: … Read more