[Solved] return list 10 times with for. I want 2 numbers to be printed on the screen in each cycle in order [closed]

If you want to cycle the list elements, you can use itertools.cycle. We can call next twice on each iteration to get two numbers at a time from the iterator. from itertools import cycle a = cycle([0,1,2,3,4,5,6]) for _ in range(10): print(f”{next(a)} – {next(a)}”) Output: 0 – 1 2 – 3 4 – 5 6 … Read more

[Solved] How do I put this into one line? [closed]

This can be put into one line in several ways. Without changing your code you could just remove the newline and indent: with open(‘output.txt’, ‘w’) as f: for item in winapps.list_installed(): print(item, file=f) Or just using unpacking and print formatting: with open(‘output.txt’, ‘w’) as f: print(*winapps.list_installed(), sep=”\n”, file=f) Which can also be done in one … Read more

[Solved] Python calling function in an function from another function

Define your function example as this:- def exemple(func_name): def dostuff1(): print(‘Stuff 1’) def dostuff2(): print(‘Stuff 2’) def dostuff3(): print(‘Stuff 3’) func_dic = { “dostuff1” : dostuff1, “dostuff2” : dostuff2, “dostuff3” : dostuff3 } return func_dic[func_name] Then call your function in the other function like this: def training(): exemple(“dostuff2”)() I hope it helps! 3 solved Python … Read more

[Solved] Write to file doesnt work “Indentation error” [duplicate]

If the rest of the code is correct, this should do: def add_sighting(session, spawn_id, pokemon): obj = Sighting( pokemon_id=pokemon[‘id’], spawn_id=spawn_id, expire_timestamp=pokemon[‘disappear_time’], normalized_timestamp=normalize_timestamp(pokemon[‘disappear_time’]), lat=pokemon[‘lat’], lon=pokemon[‘lng’], ) # Check if there isn’t the same entry already existing = session.query(Sighting) \ .filter(Sighting.pokemon_id == obj.pokemon_id) \ .filter(Sighting.spawn_id == obj.spawn_id) \ .filter(Sighting.expire_timestamp > obj.expire_timestamp – 10) \ .filter(Sighting.expire_timestamp < obj.expire_timestamp … Read more

[Solved] calling a function with input [closed]

Use True/False instead of true/false. You can consider True and False as somehow ‘keywords’ in Python. For Python scripts, you don’t use def main():. Instead, try using if __name__ == ‘__main__’: under global scope. Look at this for more info. You have to print something out rather than just return a boolean variable, by using … Read more

[Solved] Python take a variable number of inputs? [closed]

amount = int(input(“Enter the amount of numbers that you have: “)) numbers = [] for i in range(amount): new = input(‘Enter number {}: ‘.format(i+1)) numbers.append(new) print(numbers) You should probably do some reading on loops in Python. 2 solved Python take a variable number of inputs? [closed]

[Solved] Python – why is this wrong? [closed]

Luckily my crystal ball is working today so I can guess what you mean when you say it isn’t working. Of course, you might have made it easier by actually explaining, but there we go. If you just want a list of (x, y) pairs then zip is the way to go. The syntax you … Read more