[Solved] What is wrong with my class code [Python]?

You need to pass argument to your constructor. s1 = Square(1) # will call Square.__init__(self, 1) s2 = Square(2) # will call Square.__init__(self, 2) It’s not a big problem. Update I rewrite your class: import math class Square(): def __init__(self, length): #return an instance of this class with ‘length’ as the default length. self.length = … Read more

[Solved] putting float numbers in lists [closed]

Just create lists: somelist = [p1, p2] You probably want to append those to another data structure initialized outside of your loop: somelargerlist = [] for presumed_loop_variable in presumed_loop_not_shown: p1 = … p2 = … somelist = [p1, p2] somelargerlist.append(somelist) 17 solved putting float numbers in lists [closed]

[Solved] Python dictionary operations

Yes, you can do this recursively, if all you have is lists and dictionaries, then that is pretty trivial. Test for the object type, and for containers, recurse: def unwrap_data(obj): if isinstance(obj, dict): if ‘data’ in obj: obj = obj[‘data’] return {key: unwrap_data(value) for key, value in obj.items()} if isinstance(obj, list): return [unwrap_data(value) for value … Read more

[Solved] Python if and else

You don’t want to use the function random.choice in your if statement. Save the random name as a variable and check it. import random random_choice = [‘Noob’, ‘Average’, ‘Pro’, ‘Expert’] name = input(‘What is your gamername? ‘) random_name = random.choice(random_choice) print(name, ‘is a’, random_name, ‘Gamer’) if random_name == ‘Noob’: print(‘Im afraid there is nothing to … Read more

[Solved] use dictionary as a list in python

Maybe you can consider using random.sample like so. >>> import random >>> p = 2*[‘a’] + 3*[‘b’] + 4*[‘c’] + 5*[‘d’] >>> random.sample(p, 3) [‘b’, ‘b’, ‘a’] From the docs, random.sample returns a k length list of unique elements chosen from the population sequence or set. It is used for random sampling without replacement. Therefore, … Read more

[Solved] Python. Converting string into directory [closed]

This is a very weird way to handle data. I would use a nested dicts: exampleDictionary = {‘thing on ground’: {‘backpack’: {‘tea’: ‘Earl Grey’}}} print exampleDictionary[‘thing on ground’] print exampleDictionary[‘thing on ground’][‘backpack’] print exampleDictionary[‘thing on ground’][‘backpack’][‘tea’] Outputs: {‘backpack’: {‘tea’: ‘Earl Grey’}} {‘tea’: ‘Earl Grey’} Earl Grey 2 solved Python. Converting string into directory [closed]

[Solved] How i can convert ISO time format to yyyy-mm-dd hh:mm:ss using python [closed]

Try this, >>> import datetime >>> datetime.datetime.now().strftime(‘%d-%m-%Y %H:%M:%S’) ’03-08-2019 12:43:16′ If you max_startdate is string, >>> max_startdate=”2019-08-03 01:08:58.155000″ >>> max_startdate.split(‘.’)[0] ‘2019-08-03 01:08:58’ 3 solved How i can convert ISO time format to yyyy-mm-dd hh:mm:ss using python [closed]

[Solved] Regular expression in python string [closed]

This works: import re s=””‘customer is given as per below customer are given not priority below given given below customer below customer information given customer is given not as per below”’ matches = re.findall(‘customer \S+ given \S+\s\S+ below’, s) for match in matches: print(match) 14 solved Regular expression in python string [closed]