[Solved] combinations program help in python [closed]

Alright I’ve done the hard part hoping you can finish it up: tmp = [] def recal(_list): n = [] if ‘-‘ in _list: for i in 0,1: t = _list[:] t[t.index(‘-‘)] = i n.append(recall(t)) else: tmp.append(l) return l recall([‘-‘,’-‘,’0′,’1’]) for l in tmp: print int(”.join(l),2) 0 solved combinations program help in python [closed]

[Solved] Searching through database with python

Try import MySQLdb db = MySQLdb.connect(host=”localhost”, user=”user”, passwd=”password”, db=”database”) cur = db.cursor() cur.execute(“SELECT common_name , genus , species FROM table WHERE sequence LIKE ‘MDPSSID%'”) 1 solved Searching through database with python

[Solved] How to show the cost of a game using this Python [closed]

If this is python3.x you have to do it as follows: if game_list[game]>= 10: print (“The Price for this Game is: $”, game_prices[game]*1.1) For python2.7, it would be: if game_list[game]>= 10: print “The Price for this Game is: $”+game_prices[game]*1.1 solved How to show the cost of a game using this Python [closed]

[Solved] What is wrong with this programming? [closed]

Aside from several ugly antipatterns, there’s one obvious mistake/typo: Take a good look at if a > 0: kb = int(str(byte)[a:b]) else: kd = int(str(byte)[0:b]) Do you see now where your error comes from? 1 solved What is wrong with this programming? [closed]

[Solved] Python if statements [closed]

Try that (see the new indention) script_username=”test” script_password=”1″ login_username=raw_input(‘Please Enter the script username:’) login_password=getpass.getpass(‘Please Enter the script password:’) if login_password == script_password and login_username == script_username: print ” Welcome to the Script ” else: print ” your Username or Password is false ” exit() name=raw_input(“Enter your name: “) family=raw_input(“Enter your family: “) sex=raw_input(“Enter your Sex: … Read more

[Solved] NameError: name ‘num’ is not defined

num is not actually used in multiply() so there is no reason to pass it in. Instead, declare multiply() without the argument: def multiply(): ”'(num1 * num2)”’ . . And call it from __main__ like this: if maths == “Multiplication” or “m” or “x”: multiply() There seems no point in checking within multiply() whether it … Read more

[Solved] Swap two numbers in list of tuples (python)

For anyone curious, I quickly wrote a function for it. First off, the complete matching is written as a 2D list. The following function is needed before writing the main one: def index_2d(myList, v): #Returns tuple containing the position of v in the 2D list for i, x in enumerate(myList): if v in x: return … Read more

[Solved] How can I produce a file? [closed]

The answers in the comments are more pythonic, but if you want a more easily understandable example >>> books = {} >>> line = “Calculus | James Stewart” >>> parts = line.split(‘|’) # can also do title, author = line.split(‘|’) >>> books[parts[0].strip()] = parts[1].strip() >>> print(books) {‘Calculus’: ‘James Stewart’} 1 solved How can I produce … Read more

[Solved] index string by character

from itertools import zip_longest list1 = [‘one’, ‘two’, ‘twin’, ‘who’] chars = {} for i, item in enumerate(zip_longest(*list1)): set1 = set(item) if None in set1: set1.remove(None) chars[i] = max(set1, key=item.count) Without importing any library: list1 = [‘one’, ‘two’, ‘twin’, ‘who’] width = len(max(list1, key=len)) chars = {} for i, item in enumerate(zip(*[s.ljust(width) for s in … Read more

[Solved] How to print the codes in python? [duplicate]

The easiest way to print the lines of codes is through the use of the built-in functions. print open(__file__).read() Or you could just write the code in string mode and simply print them. However that obviously won’t be executable codes anymore once written in quotation marks. solved How to print the codes in python? [duplicate]