[Solved] I have been solving problems in HackerRank and I am getting ” Runtime Error :( ” again and again, for all problems. What mistake am I doing here…?

I have been solving problems in HackerRank and I am getting ” Runtime Error 🙁 ” again and again, for all problems. What mistake am I doing here…? solved I have been solving problems in HackerRank and I am getting ” Runtime Error 🙁 ” again and again, for all problems. What mistake am I … Read more

[Solved] Why the method in some class I created, ask me for input “self”? [closed]

You have to create an object of your class: class MyClass: def __init__(self,a=1,b=2): self.a=a self.b=b def function1(self): self.c=self.a/self.b + 5 return(self.c) print(MyClass().function1()) MyClass() creates an object that can be used to access attributes in the class. For a general instance: m = MyClass() print(m.function1()) 6 solved Why the method in some class I created, ask … Read more

[Solved] How does the while loop know when to stop?

The while loop stops when the function exits, and the function exits when the return statement is executed. The return statement is executed when s.find() returns -1, which means that t was no found in s when searching from last_pos + 1 onwards. solved How does the while loop know when to stop?

[Solved] Xor logic in python

The trick is to recognize that you don’t have to test all the a up to x. For a^x == a+x, then a&x == 0. So we count the number of zeroes in the bitstring of x and then out answer is 2**count -1 test = int(input()) for _ in range(test): x = int(input()) print(2**bin(x)[2:].count(‘0’) … Read more

[Solved] Counting how many times a value occurs in a json file [closed]

from collections import Counter import json from pprint import pprint with open(‘logs.txt’) as infile: data = (json.loads(line) for line in infile) counter = Counter((row[‘type’], row[‘key’]) for row in data) pprint(dict(counter)) Output: {(u’REVERSEGEOCODE’, u’04track12netics2015′): 5, (u’REVERSEGEOCODE’, u’fpOgtLY1ZF22m3va4FLkU52tsLmpaNyo’): 1, (u’SEARCH’, u’fpOgtLY1ZF22m3va4FLkU52tsLmpaNyo’): 1, (u’TILE’, u’CxIQlYBhwykcIxtYwrrbltCDiJ4xUxfN’): 3, (u’TILE’, u’fpOgtLY1ZF22m3va4FLkU52tsLmpaNyo’): 4} 1 solved Counting how many times a value occurs … Read more

[Solved] Plotting from excel to python with pandas

Check out these packages/ functions, you’ll find some code on these websites and you can tailor it to your needs. Some useful codes: Read_excel import pandas as pd df = pd.read_excel(‘your_file.xlsx’) Code above reads an excel file to python and keeps it as a DataFrame, named df. Matplotlib import matplotlib.pyplot as plt plt.plot(df[‘column – x … Read more

[Solved] Please I’m new to python and I’m trying to do a recipe app using Django. I encountered an error which is “UnboundLocalError: local variable form [closed]

you only create form if your request is POST. so if you try to call your view with get method form variable is not created. this is your code I’m gonna walk you through it. def register(request): if request.method == “POST”: form = UserCreationForm(request.POST) if form.is_valid(): username = form.cleaned_data.get(‘username’) messages.success(request,f”{username}, your account has been created!”) … Read more