[Solved] I’ve completed the code however I don’t understand what’s wrong [closed]

You’re trying to compare a str with an int. The following will fix it: def output(number): if number > 5: print(“Greater than 5”) elif number < 5: print(“Less than 5”) else: print(“It is equal to 5”) userInput = “yes” print(userInput.lower() != “no”) num = int(input(“Enter a number \n”)) output(userInput) userInput = input(“Would you like to … Read more

[Solved] AP in Python using function

You can do that in this way, Also; you can specify how many terms you want in between first and last one by the third argument. Use simple mathematics. def ap(arg1, arg2, d): diff = arg2 – arg1 for i in range(d): yield arg1 + i*(diff/(d+1)) # division by d+1 >>> list(ap(1, 6, 4)) [1.0, … Read more

[Solved] When running this code, it doesn’t actually replace the strings… Why? Also, will making this be practical?

You had a logical error there, always replacing chars in the b64ed string, so only the last of the replacement characters could actually be replaced. So you would see changes only if b64ed happened to contain the randStr[5] character, otherwise final_product would just be the exact same as b64ed. Part of your code should look … Read more

[Solved] Unable to renew random number on python

You are actually getting a new random number every loop. Your problem is here: … if DeathDoor == door: … You are comparing an integer to a string, which always yields False. The correct way is if DeathDoor == int(door) Also resetting RandomNum and DeathDoor to zero is unecessary. Since you are just beginning to … Read more

[Solved] Copying a file and then printing the absolute path to its final destination [closed]

This code should solve your problem: import os import shutil #lets say that the extension is mp4 but you can change it to the correct one file_name=”RRR_0010_V001.mp4″ file_name_parts = file_name.split(‘_’) #remove the extension for the last folder in the dir file_name_parts[2] = file_name_parts[2].replace(‘.mp4’, ”) directory = os.path.join(file_name_parts[0],file_name_parts[1],file_name_parts[2]) try: os.makedirs(directory) except FileExistsError: with open(‘errors.log’, ‘a’) as … Read more

[Solved] struck with raintrap in python

You have multiple problems with your code. Variable names could be more informative l -> left_side. This way you don’t need to have a comment on every line. You use a variable n that is not initialized to anything. Perhaps split your code into multiple functions. Then you can investigate if each function does what … Read more

[Solved] How to create a counter for each new instance of string in python?

File input.txt ##### pears oranges ##### apples grapes ##### grapes oranges ##### apples pears oranges grapes File run.py lines = [l.strip() for l in open(‘input.txt’, ‘r’).readlines()] hash_count = 0 for line in lines: if line == ‘#####’: hash_count += 1 print(line) else: print(line + ‘_’ + str(hash_count)) Run it: $ python run.py Output: ##### pears_1 … Read more

[Solved] In cmd python shows python 2.7 installed but when I write python2 it shows that it isn’t recognized as a internal file or command [duplicate]

In cmd python shows python 2.7 installed but when I write python2 it shows that it isn’t recognized as a internal file or command [duplicate] solved In cmd python shows python 2.7 installed but when I write python2 it shows that it isn’t recognized as a internal file or command [duplicate]

[Solved] Create a dictionnary from defaultdict(list) with nested list inside [closed]

Just loop through your dictionary elements, reformatting the list of lists into list of dictionary using a list comprehension. original = { ‘t0’: [[‘cat0’, [‘eagle0’]], [‘cat1’, [‘eagle1’]]], ‘t1’: [[‘cat2’, [‘eagle2’, ‘eagle3’]]] } result = [] for key, cats in original.items(): cats = [{‘cat’: cat, ‘eagles’: eagles} for cat, eagles in cats] result.append({‘t’: key, ‘cats’: cats}) … Read more