[Solved] combinations program help in python [closed]

[ad_1] 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 [ad_2] solved combinations program help in python … Read more

[Solved] Searching through database with python

[ad_1] 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 [ad_2] solved Searching through database with python

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

[ad_1] 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 [ad_2] solved How to show the cost of a game using this Python [closed]

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

[ad_1] 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 [ad_2] solved What is wrong with this programming? [closed]

[Solved] How to combine lists? (Python) [duplicate]

[ad_1] Just use zip to get tuples of values at corresponding indices in the two lists, and then cast each tuple to a list. So: [list(t) for t in zip(list1, list2)] is all you need to do. Demo: >>> list1 = [“X”, “Y”, “Z”] >>> list2 = [1, 2, 3] >>> list3 = [list(t) for … Read more

[Solved] Python if statements [closed]

[ad_1] 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 … Read more

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

[ad_1] 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 … Read more

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

[ad_1] 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: … Read more

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

[ad_1] 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 [ad_2] solved How can … Read more

[Solved] index string by character

[ad_1] 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 … Read more

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

[ad_1] 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. [ad_2] solved How to print the codes in … Read more