[Solved] How to loop back to the beginning of the code on Python 3.7

username = [‘admin’,’bill’,’Kevin’,’mike’,’nick’] while True : name =input(“Please enter a username: “) if name==’admin’ : print(“Hello “+ name + ” ,would you like to see a status report?”) break elif name in username : print(“Hello ” + name.title() + ” thank you for logging in!”) break else: print(“Who are you ” + name.title() + ” … Read more

[Solved] Need help conditionally vectorizing a list [closed]

You can use pandas: import pandas as pd l = [-1.5,-1,-1,0,0,-1,0,1.5,1,1,1,1,0,0,0,0,1,0,1,0,1.5,1,1,1,1,0,0,0,0,-1.5] s = pd.Series(l) cond1 = (s == 1.5) cond2 = (s == -1.5) cond3 = (s == 0) cond4 = ((s == 1) | (s == -1)) & (s.shift() == 0) out = pd.Series(pd.np.select([cond1, cond2, cond3, cond4],[1, -1, 0 ,0], pd.np.nan)).ffill() out.tolist() Output: [-1.0, … Read more

[Solved] builtins.TypeError TypeError

You don’t need to pass category_name, you only need the category id. The category name should be contained in each of the item fetched from the database. You’re getting an error because cat_id is not defined when the function def getCategoryItems(category_name, cat_id) is called. I would suggest, however, if you want to really get all … Read more

[Solved] Tkinter Function attached to Button executed immediately [duplicate]

The solution is to pass the function as a lambda: from Tkinter import * root =Tk() def callback(parameter): print parameter button = Button(root, text=”Button”, command=lambda: callback(1)) button.pack() root.mainloop() Also, as @nbro already correctly pointed out, the button attribute is command, not function. 1 solved Tkinter Function attached to Button executed immediately [duplicate]

[Solved] How do I calculate sine/cosine/tangent from CORDIC, Taylor Series, or alternative in Python?

The Taylor series for the sin function is straightforward to implement. Note that any reference which gives a Taylor series for a trigonometric function will assume the input is in radians, unless specified otherwise. PI = 3.141592653589793238462643383 def sin_taylor_series(x, terms=9): # map x into the range -PI/2 to PI/2 for greatest accuracy x %= 2*PI … Read more

[Solved] Why does 0 % 5 return 0?

Division is defined so that the following is always true n = q × d + r where n is the numerator (or dividend), d != 0 is the denominator (or divisor), q is the quotient, and r > 0 is the remainder. (This holds for positive and negative values; q is positive if n … Read more

[Solved] I am writing a program that generates a list of integer coordinates for all points in the first quadrant from (1, 1) to (5, 5) [closed]

In the first line you have written first_quadrant as 1 which is an integer. In the second line you are trying to use a for loop over an integer. This is not allowed and therefore the error. You could do it in many other ways. I am writing two such possible solutions. Solution 1 first_quadrant … Read more

[Solved] What principles or concepts exist to communicate between two webservers securely? [closed]

Restful web-service endpoints on each application makes reasonable sense based on the assumption you want to stick with Django/Python for this. I would suggest using Django Rest Framework and make use of token based authentication with pre-configured “shared keys” (which you can periodically rotate). With token-based auth, your keys are passed in the HTTP header … Read more

[Solved] Can I store an iterator in a file which I can read from later? Will this reduce space consumption? [closed]

Building on larsmans answer, a custom iterator can be built to do this: class my_large_num(object): def __init__(self): self.num_iterations = 0 def __iter__(self): return self def next(self): if self.num_iterations < 1: self.num_iterations += 1 return 10**200 else: raise StopIteration() You can then: import pickle pickled_repr = pickle.dumps(my_large_num()) restored_object = pickle.loads(pickled_repr) sum(restored_object) This works because underneath, iterable … Read more

[Solved] how to print string variable in python

From your question name = input(“What is your name: “) age = int(input(“How old are you: “)) year = str((2014 – age)+100) print(name + ” will be 100 years old in the year ” + year) Your code is just fine, change your input to raw_input for name variable. NOTE: raw_input returns a string, input … Read more