[Solved] how to solve this problem:Multi Line Task: Hello World (Easy one) on codewars.com [closed]

Interesting puzzle. To get around the need to explicitly pass an argument to f, you can create a class with t (which is type), and use k to create a __new__ method that returns ‘Hello, world!’. Since __new__ is a class method, _ would become the class object when an instance is instantiated: f=t(”,(),{‘__new__’:k(‘Hello, world!’)}) … Read more

[Solved] algorithm that outputs the cost of electric bill including tax [closed]

I believe you got the “per kilowatt hour” concept a bit confused. Looks like instead of dividing the “cost per kilowatt hour” by the “kilowatt hours consumed”, you should be multiplying. E.G. basecost = float(cost * kilohour) When I did that, I got what looked to be a nominal bill. craig@Una:~/Python_Programs/Kilowatt$ python3 Killowatt.py Enter watts … Read more

[Solved] Issue with if-else statements [closed]

You are indeed missing something basic – namely, that the output of your function doesn’t depend on answer at all. No matter what you feed in as answer, because 6 > 5 is always True, it will always return the result of that case. What you need is def greater_less_equal_5(answer): if answer > 5: return … Read more

[Solved] How to merge two dictionaries with same keys and keep values that exist in the same key [closed]

def intersect(a, b): a, b = set(a), set(b) return list(a & b) def merge_dicts(d1, d2): return {k: intersect(v1, v2) for (k, v1), v2 in zip(d1.items(), d2.values())} dictionary_1 = {‘A’ :[‘B’,’C’,’D’],’B’ :[‘A’]} dictionary_2 = {‘A’ :[‘A’,’B’], ‘B’ :[‘A’,’F’]} merge = merge_dicts(dictionary_1, dictionary_2) print(merge) # {‘A’: [‘B’], ‘B’: [‘A’]} 4 solved How to merge two dictionaries with … Read more

[Solved] If you were an employer looking at a novice coder, what would you consider a complex enough project to consider them a capable programmer? [closed]

Plenty of well written questions and answers on StackOverflow would go a long way towards convincing me of both your ability to think critically and to communicate with a team. Companies in my time were happy if you could recreate a couple of dozen Unix command line filters. Nowadays that is not enough. Cross platform … Read more

[Solved] I am trying to swap the two elements in the list, but after the first swap it keeps getting swapped as it fits the condition to be swapped

num = [3, 21, 5, 6, 14, 8, 14, 3] num.reverse() for i in range(len(num)-1): if num[i] % 7 == 0: num[i – 1], num[i] = num[i], num[i – 1] num.reverse() print(“The required answer :”, num) solved I am trying to swap the two elements in the list, but after the first swap it keeps … Read more

[Solved] Faulty input behavior with conditionals [closed]

Your this part of code : if (GenderSelect.lower() == “f”): print(“Name: ” + NameCreate + “\nAge: ” + str(AgeSelect) + “\nGender: Female\n”) gerror = 0 if (not(GenderSelect.lower() == “f” GenderSelect.lower() == “m”)): gerror = 1 should be : elif (GenderSelect.lower() == “f”): print(“Name: ” + NameCreate + “\nAge: ” + str(AgeSelect) + “\nGender: Female\n”) gerror … Read more

[Solved] Extract a substring that starts with “http” and ends with “.mp3” from a string

You can use regular expressions for what you describe: In [48]: s=”Link: http://google.com/song.mp3 Another link, http://yahoo.com/another_song.mp3″ In [49]: re.findall(‘http.*?mp3’, s) Out[49]: [‘http://google.com/song.mp3’, ‘http://yahoo.com/another_song.mp3’] 1 solved Extract a substring that starts with “http” and ends with “.mp3” from a string

[Solved] Python issue with “input” [closed]

Do you mean something like this? answer1 = input(“what device do you have? “) answer2 = input(“looks like you are using ‘{0}’ as a device, but why? “.format(answer1)) print(answer2) solved Python issue with “input” [closed]

[Solved] Hi , i am executing a python script using php but I do not want the page to refresh when a button is clicked because i have embedded other pages too [closed]

Use JQUERY Ajax $.post(“url to process data”,{data:data}, function(response){ //do something with the response )}; 5 solved Hi , i am executing a python script using php but I do not want the page to refresh when a button is clicked because i have embedded other pages too [closed]

[Solved] what is meaning of string inside array python

When you use x[y] = z, it calls the __setitem__ method. i.e. x.__setitem__(y, z) In your case, CmdBtn[‘menu’] = CmdBtn.menu means CmdBtn.__setitem__(‘menu’, CmdBtn.menu) The Menubutton class does indeed provide a __setitem__ method. It looks like this is used to set a “resource value” (in this case CmdBtn.menu) for the given key (‘menu’). solved what is … Read more