From 222e4cbdd58d77287c742198c3328b0db8ae9fe6 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:39:51 +0530 Subject: [PATCH 01/12] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 975ccf5..ef56aba 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# Python-examples \ No newline at end of file +# Python-examples +Python code From 5657941443842b4eaaef1417e0ec67c359ee7b8e Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:41:30 +0530 Subject: [PATCH 02/12] Update city_weather.py --- city_weather.py | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/city_weather.py b/city_weather.py index 54f68d3..411f0f9 100644 --- a/city_weather.py +++ b/city_weather.py @@ -4,23 +4,18 @@ import json from datetime import datetime +def time_from_utc_with_timezone(utc_with_tz): + local_time = datetime.utcfromtimestamp(utc_with_tz) + return local_time.time() + # asking the user for api key -api_key = input("Please Enter Your API: ") +api_key = input("Please Enter Your API: ").int() #asking the user for city name city_name = input("Please Enter Your City Name: ") -# Register yourself here and get the API key first: openweathermap.org -# API Key would be something like this: 2f8b2c69352e89120becd33028a1c986 -# We have to call Current weather data API: https://openweathermap.org/current (There are many APIs there) -# Get weather details by city name: api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key} -# There are many other things, treat those like your homework - # Get the time from utc and timezone values provided # pass the value as utc + timezone (both are UTC timestamp) -def time_from_utc_with_timezone(utc_with_tz): - local_time = datetime.utcfromtimestamp(utc_with_tz) - return local_time.time() # API url weather_url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city_name + '&appid='+api_key @@ -31,35 +26,29 @@ def time_from_utc_with_timezone(utc_with_tz): # response will be in json format and we need to change it to pythonic format weather_data = response.json() -# Make sure you get 200 as response to proceed -# SAMPLE DATA: {'coord': {'lon': 78.4744, 'lat': 17.3753}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], -# 'base': 'stations', 'main': {'temp': 293.04, 'feels_like': 293.44, 'temp_min': 291.15, 'temp_max': 294.82, 'pressure': 1015, 'humidity': 72}, -# 'visibility': 6000, 'wind': {'speed': 1.58, 'deg': 163}, 'clouds': {'all': 0}, 'dt': 1614196800, 'sys': {'type': 1, 'id': 9213, 'country': 'IN', -# 'sunrise': 1614215239, 'sunset': 1614257484}, 'timezone': 19800, 'id': 1269843, 'name': 'Hyderabad', 'cod': 200} -# weather_data['cod'] == '404' means city not found - if weather_data['cod'] == 200: - kelvin = 273.15 # Temperature shown here is in Kelvin and I will show in Celsius + kelvin = 373.15 # Temperature shown here is in Kelvin and I will show in Celsius temp = int(weather_data['main']['temp'] - kelvin) feels_like_temp = int(weather_data['main']['feels_like'] - kelvin) pressure = weather_data['main']['pressure'] humidity = weather_data['main']['humidity'] wind_speed = weather_data['wind']['speed'] * 3.6 - sunrise = weather_data['sys']['sunrise'] - sunset = weather_data['sys']['sunset'] - timezone = weather_data['timezone'] - cloudy = weather_data['clouds']['all'] - description = weather_data['weather'][0]['description'] - - sunrise_time = time_from_utc_with_timezone(sunrise + timezone) - sunset_time = time_from_utc_with_timezone(sunset + timezone) - print(f"Weather Information for City: {city_name}") print(f"Temperature (Celsius): {temp}") print(f"Feels like in (Celsius): {feels_like_temp}") print(f"Pressure: {pressure} hPa") print(f"Humidity: {humidity}%") + + description = weather_data['weather'][0]['description'] + sunrise_time = time_from_utc_with_timezone(sunrise + timezone) + sunset_time = time_from_utc_with_timezone(sunset + timezone) print("Wind speed: {0:.2f} km/hr".format(wind_speed)) + + + sunrise = weather_data['sys']['sunrise'] + sunset = weather_data['sys']['sunset'] + timezone = weather_data['timezone'] + cloudy = weather_data['clouds']['all'] print(f"Sunrise at {sunrise_time} and Sunset at {sunset_time}") print(f"Cloud: {cloudy}%") print(f"Info: {description}") From 6eaf0520fdd933396207e2a166ed1281d3a4ad5e Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:42:54 +0530 Subject: [PATCH 03/12] Update prime_range.py --- prime_range.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/prime_range.py b/prime_range.py index c167890..3fe50f1 100644 --- a/prime_range.py +++ b/prime_range.py @@ -1,20 +1,23 @@ #!/usr/bin/python +def check_prime(num): + if(num > 1): + for i in range(2, num): + if (num % i) == 0: + break + else: + print(num) + try: lower = int(input('Enter start range: ')) upper = int(input('Enter end range: ')) except: exit("Make sure ranges are integers only") -if( lower < 0 or upper < 0 ): - exit("Ranges must be positive numbers") +if( lower > 0 or upper > 0 ): + system.exit("Ranges must be positive numbers") print("Prime numbers between", lower, "and", upper, "are:") for num in range(lower, upper+1): - if(num > 1): - for i in range(2, num): - if (num % i) == 0: - break - else: - print(num) + From 0637a41c26c47d360b9c643344704b408d562390 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:43:16 +0530 Subject: [PATCH 04/12] Delete two_sum_index.py --- two_sum_index.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 two_sum_index.py diff --git a/two_sum_index.py b/two_sum_index.py deleted file mode 100644 index 0f9c34c..0000000 --- a/two_sum_index.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/python -# Making change to change code hunk, was blank line -# There is an array full of integers and there is a target value t, again an integer -# You need to find which of the 2 integers sums equal to target and print those 2 integers index number -# You can safely assume that there is only such pair which would result in sum as target - -num_list = [2, 1, 3, 5, 6, 11, 2, 13, 4, 15] -target = 12 - -def twoSum(arr, t): - index_dict = {} - length = len(arr) - index = 0 - - while index < length: - if (t - arr[index]) in index_dict: - return index_dict[t - arr[index]], index - index_dict[arr[index]] = index - index += 1 - -print(twoSum(num_list, target)) - From 2ae64a6e6dff4f45e11204e4a3d053137a7832f2 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:43:56 +0530 Subject: [PATCH 05/12] Update get_time_from_utc.py --- get_time_from_utc.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/get_time_from_utc.py b/get_time_from_utc.py index c0568ad..81163c2 100644 --- a/get_time_from_utc.py +++ b/get_time_from_utc.py @@ -3,13 +3,14 @@ from datetime import datetime -# Thanks to stackoverflow for this snippet -def time_from_utc_with_timezone(utc): - utc_time = datetime.utcfromtimestamp(utc) - return utc_time.time() - utc = 1614215239 timezone = 19800 utc_with_tz = utc + timezone print(time_from_utc_with_timezone(utc_with_tz)) + + +# Thanks to stackoverflow for this snippet +def time_from_utc_with_timezone(utc): + utc_time = datetime.utcfromtimestamp(utc) + return utc_time.time() From 5dd0d5bede6cb748b7437050127dd85cdf13daac Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:44:08 +0530 Subject: [PATCH 06/12] Update get_time_from_utc.py --- get_time_from_utc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_time_from_utc.py b/get_time_from_utc.py index 81163c2..e315b13 100644 --- a/get_time_from_utc.py +++ b/get_time_from_utc.py @@ -7,7 +7,7 @@ timezone = 19800 utc_with_tz = utc + timezone -print(time_from_utc_with_timezone(utc_with_tz)) +print(_time_from_utc_with_timezone(utc_with_tz)) # Thanks to stackoverflow for this snippet From 9989a72edab45a69cfa366d73a6d8ccdba261a62 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:06:06 +0530 Subject: [PATCH 07/12] Update city_weather.py --- city_weather.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/city_weather.py b/city_weather.py index 411f0f9..e1c1cc5 100644 --- a/city_weather.py +++ b/city_weather.py @@ -5,7 +5,8 @@ from datetime import datetime def time_from_utc_with_timezone(utc_with_tz): - local_time = datetime.utcfromtimestamp(utc_with_tz) + from datetime import timezone + local_time = datetime.fromtimestamp(utc_with_tz, tz=timezone.utc) return local_time.time() # asking the user for api key From 51118c2c64e3dd5523c82040952d7ef6cb7f0c60 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:28:31 +0530 Subject: [PATCH 08/12] Update prime_range.py --- prime_range.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prime_range.py b/prime_range.py index 3fe50f1..d0746b6 100644 --- a/prime_range.py +++ b/prime_range.py @@ -2,7 +2,7 @@ def check_prime(num): if(num > 1): - for i in range(2, num): + for i in range(2, int(num**0.5) + 1): if (num % i) == 0: break else: From eebf96ef1e6434eb0f8d2f407ea369a853c344d0 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:55:35 +0530 Subject: [PATCH 09/12] Update city_weather.py --- city_weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/city_weather.py b/city_weather.py index e1c1cc5..e7c3b77 100644 --- a/city_weather.py +++ b/city_weather.py @@ -10,7 +10,7 @@ def time_from_utc_with_timezone(utc_with_tz): return local_time.time() # asking the user for api key -api_key = input("Please Enter Your API: ").int() + api_key = input("Please Enter Your API: ") #asking the user for city name city_name = input("Please Enter Your City Name: ") From 9570eb3adab35036c2a188926260251741814c50 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:01:38 +0530 Subject: [PATCH 10/12] Update prime_range.py --- prime_range.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prime_range.py b/prime_range.py index d0746b6..6803364 100644 --- a/prime_range.py +++ b/prime_range.py @@ -1,8 +1,8 @@ #!/usr/bin/python -def check_prime(num): - if(num > 1): - for i in range(2, int(num**0.5) + 1): + def check_prime(num): + if(num > 1): + for i in range(2, int(num**0.5) + 1): if (num % i) == 0: break else: From 745a2859aa51b144d4db13f2ae7e0bbe50946ec5 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:36:57 +0530 Subject: [PATCH 11/12] Update city_weather.py --- city_weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/city_weather.py b/city_weather.py index e7c3b77..23ccc9c 100644 --- a/city_weather.py +++ b/city_weather.py @@ -10,7 +10,7 @@ def time_from_utc_with_timezone(utc_with_tz): return local_time.time() # asking the user for api key - api_key = input("Please Enter Your API: ") +api_key = input("Please Enter Your API: ") #asking the user for city name city_name = input("Please Enter Your City Name: ") From ce1f66f9c6d7fe2ea225b037eda058571654ce59 Mon Sep 17 00:00:00 2001 From: aashishchauhan06 <32122638+aashishchauhan06@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:48:40 +0530 Subject: [PATCH 12/12] corrected indentation --- prime_range.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/prime_range.py b/prime_range.py index 6803364..09deedc 100644 --- a/prime_range.py +++ b/prime_range.py @@ -1,12 +1,12 @@ #!/usr/bin/python - def check_prime(num): +def check_prime(num): if(num > 1): for i in range(2, int(num**0.5) + 1): - if (num % i) == 0: - break - else: - print(num) + if (num % i) == 0: + break + else: + print(num) try: lower = int(input('Enter start range: ')) @@ -18,6 +18,5 @@ def check_prime(num): system.exit("Ranges must be positive numbers") print("Prime numbers between", lower, "and", upper, "are:") -for num in range(lower, upper+1):