[Solved] Python restart for loop

By restart the loop i’m assuming u mean call it again the easiest way to do is would be to make it a recursive function def fn(): for index, line in enumerate(lines): if line[:8] == Token.INCLUDE: system(“python3 {} {}”.format(argv[0], argv[1])) del lines[index] #make sure to add your conditions else it will go into an infinite … Read more

[Solved] how do u make a program that checks many txt files [closed]

I’m not sure if this is what you are asking, but I interpreted this as list the files in a given directory, and then check if the input is in the file. import os string = input(“Please type the input “) directory = “c://files//python” for file in os.listdir(directory): if file.endswith(“.txt”): filecontent = open(file, “r”) if … Read more

[Solved] How to draw a histogram from existing bin values

Since you already have binned data, just use pyplot.errorbar or add yerr kwarg to bar plot from matplotlib import pyplot as plt plt.errorbar( [n/len(bins) for n, x in enumerate(bins)], [x[0][0] for x in bins], yerr = [x[0][1]**0.5 for x in bins], marker=”_”, fmt=”.”) plt.bar( [n/len(bins) for n, x in enumerate(bins)], [x[0][0] for x in bins], … Read more

[Solved] Python String concatenation with in double quotes [closed]

That isn’t a concatenation: you’re not appending this to anything else. It’s only a value substitution. Thus, you should (1) use the variable name, rather than a string; (2) leave out the concatenation attempt. “device-id”: d1, This should substitute the desired value of varibale d1. solved Python String concatenation with in double quotes [closed]

[Solved] How do I create a scoring system in Python? [closed]

def QuestionSet1(): print(“Challenge level 1 has being selected.”) print(“Can you translate these words into french?”) a=input(‘Q1. Hello! :’) score = 0 if ‘bonjour’ in a.lower(): score = score + 1 print(‘Correct!’) else: print(‘Wrong! ‘+’Its Bonjour’) print(‘You have finished and scored’, score, ‘out of 10’) You would need make a reference to score before you give … Read more

[Solved] How to get all seperate all equal pairs from a list in python

print [a for a,b in zip(my_list[::2],my_list[1::2]) if a == b] you may need to sort my_list first … my_list = sorted(my_list) print [a for a,b in zip(my_list[::2],my_list[1::2]) if a == b] Im not at all sure this solves your issue. def do_this_weird_thing(a_list): from itertools import groupby for grp,item in groupby(sorted(a_list)): item = list(item) yield [grp] … Read more

[Solved] Python questions about else and elseif [closed]

Yes off course! It will work like that but it’s only for this condition in which you have only one condition so the compiler checks whether it’s true or not but what if there’s more than one conditions ?? Also not using elif will allow the program to output the other print statement, but using … Read more