[Solved] Grocery Store for Python

I think the problem is in the part where you insert your item into the cartList. You only insert the item, not the money with it. So in the return part, it must be: if ask == ‘return’: ret = input(‘What item do you want to return?\n’) for i in cartList: if ret==i: … Or … Read more

[Solved] Pass variables through functions in Python 3

Your start function explicitly allows access to a global variable named var. As evidenced by your error, you have no such variable defined. Please initialize the variable before the function: var = 25 def start(): global var # the rest of your function # goes here after global var 3 solved Pass variables through functions … Read more

[Solved] Project Euler # 8- Find biggest product of n adjacent digits in number. Code works only for some values of n [closed]

I think the issue has to do with you’re getting your substrings. You’re slicing a multiline string, and so some of your slices will include a newline character instead of a digit. Though your multiplication code will ignore those newlines, they still matter since they change the number of actual digits in the multiplication. If … Read more

[Solved] how get input of multiple lines

Is this what you are after? >>> d=[] >>> while(True): … s=raw_input() … if s==””:break … temp = [s] … d.append(temp) … a,b,7-6,7-6,6-3 c,d,7-4,7-6,6-2 e,f,6-4,7-6,6-2 >>> d [[‘a,b,7-6,7-6,6-3’], [‘c,d,7-4,7-6,6-2’], [‘e,f,6-4,7-6,6-2’]] This makes a list item out of the input and then appends that list to your main list d You now should be able to … Read more

[Solved] Run python code from a certain point

It sounds from your question like you have some lines at the beginning of a script which you do not want to process each time you run the script. That particular scenario is not really something that makes a lot of sense from a scripting point of view. Scripts are read from the top down … Read more

[Solved] Why it doesn’t return anything?

def esvocal(letter): vocal =[ “a”,”e”,”i”,”o”,”u”] vocalup = [“A”,”E”,”I”,”O”,”U”] if letter in vocal and letter in vocalup: return True else: return False esvocal(“s”) esvocal(“a”) Python really cares about indentation Use in instead of == 1 solved Why it doesn’t return anything?

[Solved] How to find specific word in a text file?

This is one way to approach the problem. As you can see, you can do everything with python’s builtin strings. Note that use str.lower().strip() to normalize the search terms and the menu items before comparing them. That will give more generous results and not punish users for inputting extra spaces, and is usually a good … Read more

[Solved] TypeError: Car() takes no arguments

Your program is missing constructor and hence the error. Also do note that you are probably referring to __repr__ and not __rep__. You final code should look something like this – class Car: # In your code, this constructor was not defined and hence you were getting the error def __init__(self,name,year,model): self.name = name self.year_built … Read more

[Solved] How to flatten a nested dictionary? [duplicate]

You want to traverse the dictionary, building the current key and accumulating the flat dictionary. For example: def flatten(current, key, result): if isinstance(current, dict): for k in current: new_key = “{0}.{1}”.format(key, k) if len(key) > 0 else k flatten(current[k], new_key, result) else: result[key] = current return result result = flatten(my_dict, ”, {}) Using it: print(flatten(_dict1, … Read more

[Solved] How to filter out only the number part (800000010627, 800000010040 and so on) from a list?

The easiest way: just cut the needed part from your bytes: only_numbers = [item[18:] for item in initial_list] This expression will create a new list named only_numbers with numbers extracted from original list items. Note that this method simply omits the first 17 symbols, so, if prefix part of your initial data will change in … Read more

[Solved] Addition function in Python is not working as expected

You don’t need the functions nor the sum or multiply variables, just put the operation in str.format(), and you were missing the last position. # def addition(num1,num2): # return num1+num2 # def multiplication(num1,num2): # return num1*num2 print(“1.addition”) print(“2.multiplication”) choice = int(input(“Enter Choice 1/2”)) num1 = float(input(“Enter First Number:”)) num2 = float(input(“Enter Second Number:”)) # sum … Read more