[Solved] Python While Statements

Okay, well generally you might do something like this def confirm_with_user(): user_data = “” while user_data not in “YyYesNnNo”: user_data = input(“Are you sure? (Y/N) “) return user_data.lower() in “yes”: Then at the point in your code when you want to confirm with your user you just do if confirm_with_user(): #proceed… else: #They don’t want … Read more

[Solved] Python 3.6: when a value in a list changes, find the sum of the values in another list?

Now that I understand that the list A itself is not going to change, but you expressed the idea of change meaning that the list has partitions where there are adjacent elements that are different, then a different solution comes to mind: Given your original data: A = [‘1′,’1′,’1′,’3′,’3′,’4’] B = [‘5′,’9′,’3′,’4′,’8′,’1’] We can use … Read more

[Solved] JOINning two List-of-Lists to one [closed]

Just use Pandas to convert your lists (income and Expenses) into Dataframes, merge them (in this case it’s basically an inner join on Year and Month) and then convert the Dataframe you get into a list of lists. df1 = pd.DataFrame(income, columns=[“Year”, “Month”, “X”]) df2 = pd.DataFrame(Expenses, columns=[“Year”, “Month”, “Y”]) joined = df1.merge(df2, on=[“Year”, “Month”]).values.tolist() … Read more

[Solved] Python – ” AttributeError: ‘str’ object has no attribute ‘Tc’ (Tc is one of the arguments) [closed]

It’s here: def preos(molecule, T, P, plotcubic=True, printresults=True): Tr = T / molecule.Tc # reduced temperature … preos(“methane”, 160, 10, “true”, “true”) You’re clearly passing “methane” into the preos function as a string, then trying to call .Tc on that string. The error is saying exactly that. This doesn’t have anything to do with IPython. … Read more

[Solved] How Can I Find For Example *.mp3 Files From All Directories Of My System? [closed]

If you’re using python, os.walk can help you. Simple code like this can work: import os for data in os.walk(‘d:\\music’): # where to start searching dir_path, folders, files = data for f in files: if f.lower().endswith(‘.mp3’): print(os.path.join(dir_path, f)) 0 solved How Can I Find For Example *.mp3 Files From All Directories Of My System? [closed]

[Solved] How to get the min value for the first two columns and the max value for the next two in a list of 4 columns in python? [closed]

Use min(list) to get the minimum value across a list use max(list) to get maximum value across a list data = [ [30, 30, 20], [10, 5, 10], [20, 20, 30], [8, 20, 10] ] new_list = [] for i in range(4): if i < 2: new_list.append(min(data[i])) else: new_list.append(max(data[i])) print(new_list) # Output # [20, 5, … Read more

[Solved] How do I make it so that the code will ask you your name again if the user answers no after my if statement?

Just a simple and quick answer, maybe there is easier way. fullName = input(“Hello there, what is your name?”) fName, sName = fullName.split() print(“So, your first name is”, fName) print(“and your second name is”, sName) answer = input(“Is this correct?”) while not (answer == “Yes” or answer == “yes”): fullName = input(“Hello there, what is … Read more