[Solved] Join 2 elements of a list [closed]

To combine two items of two lists as string you need to iterate through both lists at the same time and concatenate the two items as strings. list1 = [1, 2, 3, 4] list2 = [‘a’, ‘b’, ‘c’, ‘d’] list3 = [str(x) + str(y) for x, y in zip(list1, list2)] print(list3) the output will be: … Read more

[Solved] Create or open file in python [closed]

PEP8 suggests you to use: with open(‘test.txt’, ‘a+’) as f: f.write( “Your new content” ) The with statement is better because it will ensure you always close the file, even if an exception is raised. Example adapted from: http://docs.python-guide.org/en/latest/writing/style/#pep-8 solved Create or open file in python [closed]

[Solved] Python amount of days in a month with a given year and month? [closed]

You can do all sorts of things with the calendar module: import calendar year = int(raw_input(‘Enter year: ‘)) month = int(raw_input(‘Enter month number: ‘)) print(calendar.monthrange(year, month)[1]) This considers leap years just fine, too. Example: Enter year: 2012 Enter month number: 2 29 solved Python amount of days in a month with a given year and … Read more

[Solved] Writing only lower case letters to file in Python

Code input_f = input(“Enter the file name to read from: “) output_f = input(“Enter the file name to write to… “) fw = open(output_f, “w”) with open(input_f) as fo: for w in fo: for c in w: if c.isalpha(): fw.write(c.lower()) if c.isspace(): fw.write(‘\n’) fo.close() fw.close() input.txt HELLO 12345 WORLD 67890 UTRECHT 030 dafsf434ffewr354tfffff44344fsfsd89087uefwerwe output.txt hello … Read more

[Solved] I have an error in my program that python detected. Plus im sure there are more errors. Please fix ^-^

This is a basic scope problem. Nonlocal variables by default have read-only access in functions, assignment to a variable with the same name as a variable outside of the function will result in a new, empty, local variable being created. Adding a global Money line at the top of each function that is supposed to … Read more

[Solved] How to perform this printing in for loop?

Use zip and slices >>> for i,j in zip(en[::2],en[1::2]): … print(“{}{}”.format(i,j)) … 12 34 56 As Steven Rumbalski mentions in a comment you can also do >>> it = iter(en) >>> for i,j in zip(it, it): … print i,j … 1 2 3 4 5 6 it here is an iterator over the list. Hence … Read more

[Solved] what is the meaning of this python code:

The format-string “<L” in the expression struct.pack(“<L”,self.src) means that pack interpretes the value in self.src as little-endian ordered unsigned long value. The endianess is a convention, which determines in which direction a sequence of bits are interpreted as a number: from (Big-endian) left to right, or from (Little-endian) right to left. Afterwards the unsigned long … Read more

[Solved] MD5 with more than one parameter [closed]

Try this, basically you can concatenate the three strings as a single string and use the combined string as the input for the md5 function >>> import hashlib >>> value1 = “value1” >>> value2 = “value2” >>> value3 = “value3” >>> hashlib.md5(value1 + value2 + value3).hexdigest() ‘ceba206ca4802a60ca07a411905111b8’ solved MD5 with more than one parameter [closed]

[Solved] I can’t fix an annoying error in my script [closed]

Your while condition will be True if UserHand is any non-empty value, like ‘a’, or ‘3333’, because of UserHand or UserHand_Retry…. since or needs only one of these to be True and UserHand will be evaluated as True if it’s a non-empty string. while UserHand not in [“Rock”, “Paper”, “Scissors”]: Also, be careful with multiple … Read more