[Solved] Bad Request in Python

maybe this will help import requests city = input(“What is the name of the city?: “) url= “http://api.openweathermap.org/data/2.5/weather?q={city}&appid=*************”.format(city=city) response = requests.get(url) print(response) 2 solved Bad Request in Python

[Solved] Fastest way to read file searching for pattern matches

‘grep’ contains decade’s worth of optimizations, and re-implementing it in any programming language, not just Python, will be slower. *1 Therefore, if speed is important to you, your technique of calling ‘grep’ directly is probably the way to go. To do this using ‘subprocess’, without having to write any temporary files, use the ‘subprocess.PIPE’ mechanism: … Read more

[Solved] How do I make my if statement actually do something

def attempt_function(): number_of_attempts = 0 saidpassword = “” while saidpassword != password: number_of_attempts + 1 saidpassword = input(“the password you entered is incorrect, please try again\n”) if number_of_attempts > 3: print(“You have entered the wrong password too many times, please try again later”) break saidpassword = input(“the password you entered is incorrect, please try again\n”) … Read more

[Solved] Vacation price program Python [closed]

Your trip_cost is messed up. It never calculates total_cost, and tries to call a nonexistent function. Here’s my guess on what you meant: def trip_cost(city, days): nights = days – 1 total_cost = plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(nights) return total_cost 3 solved Vacation price program Python [closed]

[Solved] Adding the sorted elements in list

You can do that as follows: from collections import defaultdict a = [(1,22),(1,22),(2,29),(2,16),(3,56),(4,32),(4,12)] b = defaultdict(lambda: 0) for i,j in a: b[i] += j >>> print b {1:44, 2:45, 3:56, 4:44} DEMO 4 solved Adding the sorted elements in list

[Solved] How can you initialise an instance in a Kivy screen widget

You have two __init__() methods in ProfileWindow. The second redefines, overwriting the first, and does not create the localId attribute. Your one and only __init__() method in ProfileWindow should be: def __init__(self, **kwargs): super(ProfileWindow, self).__init__(**kwargs) self.localId = None The next problem is that you are creating 3 instances of ProfileWindow. You only need one. So … Read more

[Solved] Practice Linux Shell Scripting

Consider adding a counter, bump it up on every line, and print the counter with every line. Also note fixes to set log_file, update to read command. log_file=”/home/user/log.txt” line_no=0 while read -r line do line_no=$((line_no+1)) printf “%d. %s\n” $line_no “$line” done < “$log_file” One alternative to consider is to call the nl utility, which performs … Read more

[Solved] Why is list comprehension so prevalent in python? [closed]

I believe the goal in this case to make your code as concise and efficient as possible. At times it can seem convoluted, but the computer looping through multiple lines as opposed to a single line adds processing time, which in large applications and across many iterations can cause some delays. Additionally, although it seems … Read more

[Solved] How to modify specific line in file [closed]

In general you don’t want to modify the contents of files directly (in-place) unless the data is formatted in fixed structures. The most common approach would be to rename the existing file, opening it to read, and opening a new file by the same name for write access. Then stream through the input data, performing … Read more