Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit a1dd103

Browse files
authored
Merge pull request #1 from ankitdobhal/master
Updating my forked repo
2 parents 6d59af5 + 04bac45 commit a1dd103

File tree

87 files changed

+3524
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3524
-40
lines changed

Basic-Scripts/Compress_the_string.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from itertools import groupby
2+
uncompressed = str(input("Enter string to compress: ")) # user input for string
3+
print(*[(len(list(value)), str(key)) for key, value in groupby(uncompressed)]) # logic to print occurence of values in string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Geocoding and Reverse Geocoding
2+
3+
#### This script takes an address and return its latitude and longitude.This process is called geocoding
4+
#### It can also perform the opposite operation that is take latitude, longitude and provide address.
5+
6+
#### I have used the LocationIQ website's geocoding api inorder to solve this problem.
7+
8+
#### In order to run this script you need to have a private token which is just a key for the api..
9+
10+
#### To obtain your own private token create a *free account* at https://locationiq.com/ and replace my private token with yours.
11+
12+
#### Remember, *don't share* your private token with anyone if you use your personal email for account creation.
13+
14+
#### Install the dependencies by using:
15+
16+
pip install -r requirements.txt
17+
18+
#### An Example of the script in action:
19+
20+
<img src="Sample.PNG" alt="Sample">
21+
22+
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import requests
2+
import sys
3+
4+
# If you want your own private_token please refer the README file for this script.
5+
private_token = "<Your Private Token>"
6+
7+
while True:
8+
choice = input(
9+
"Type G for geocoding , type R for reverse geocoding and type Q to quit the script:")
10+
print()
11+
12+
# If the user choose to perform Geocoding
13+
if choice.upper() == 'G':
14+
# Base Url for geocoding
15+
url = "https://us1.locationiq.com/v1/search.php"
16+
17+
address = input("Input the address: ")
18+
19+
# Parameters for the geocoding url
20+
data = {
21+
'key': private_token,
22+
'q': address,
23+
'format': 'json'
24+
}
25+
26+
response = requests.get(url, params=data)
27+
28+
# To run only if we get success response
29+
if response.status_code == 200:
30+
latitude = response.json()[0]['lat']
31+
longitude = response.json()[0]['lon']
32+
33+
print(f"The latitude of the given address is: {latitude}")
34+
print(f"The longitude of the given address is: {longitude}")
35+
print()
36+
else:
37+
sys.exit("Cant find what you where looking for")
38+
39+
# If the user choose to perform Reverse Geocoding
40+
elif choice.upper() == 'R':
41+
# Base Url for reverse geocoding
42+
url = "https://us1.locationiq.com/v1/reverse.php"
43+
44+
latitude_reverse = input("Enter the latitude: ")
45+
longitude_reverse = input("Enter the longitude: ")
46+
47+
# Parameters for the reverse geocoding url
48+
data = {
49+
'key': private_token,
50+
'lat': latitude_reverse,
51+
'lon': longitude_reverse,
52+
'format': 'json'
53+
}
54+
55+
response = requests.get(url, params=data)
56+
57+
# To run only if we get success response
58+
if response.status_code == 200:
59+
address = response.json()['display_name']
60+
print(f"The address is: {address}")
61+
print()
62+
else:
63+
print("Cant find what you where looking for.")
64+
65+
# If the user choose to Quit the program
66+
elif choice.upper() == 'Q':
67+
sys.exit("Thanks for using the script")
68+
69+
# To make sure only valid input is provided
70+
else:
71+
print("Please make a valid choice")
72+
print()
73+
74+
#Sample Input - Output:
75+
76+
#If you choose Geocoding:
77+
78+
#Address(Input): Rashtrapati Bhavan
79+
#Latitude(Output): 28.614458
80+
#Longitude(Output): 77.199594
81+
82+
#If you choose Reverse-Geocoding:
83+
84+
#Latitude(Input): 28.614458
85+
#Longitude(Input): 77.199594
86+
#Address(Output): Rashtrapati Bhavan, Rajpath, Presidential Estate, Chanakya Puri Tehsil, New Delhi, Delhi, 110004, India
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2020.6.20
2+
chardet==3.0.4
3+
idna==2.10
4+
requests==2.24.0
5+
urllib3==1.25.10

Basic-Scripts/README.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# Basic-Scripts
2-
Basic-Scripts is a collection of basic python scripts for newbies in python to understand basic concept of python programming.
3-
- Data Struture in python
4-
- Conditional
5-
- Loop
6-
- Exception Handling
7-
- Algorithms
8-
- OOP
9-
- Class
10-
- Object
1+
#Basic-Scripts
2+
Basic-Scripts is a collection of basic python scripts for newbies in python to understand basic concept of python programming.
3+
-Data Structure in python
4+
-Conditional
5+
-Loop
6+
-Exception handling
7+
-Algorithms
8+
-OOP
9+
-Class
10+
-Object
11+
12+
13+

Basic-Scripts/Rock_paper_scissor.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon Aug 17 14:24:23 2020
4+
5+
@author: Gulshan
6+
"""
7+
# Function rock_paper_scissor--->
8+
def rock_paper_scissor(num1,num2,bit1,bit2):
9+
play_pos1=int(num1[bit1])%3 #Play Position For Player 1
10+
play_pos2=int(num2[bit2])%3 #Play Position For Player 2
11+
if(player_one[play_pos1]==player_two[play_pos2]):
12+
print("Draw")
13+
elif(player_one[play_pos1]=="Rock" and player_two[play_pos2]=="Scissor"):
14+
print("Player one wins!!")
15+
elif(player_one[play_pos1]=="Rock" and player_two[play_pos2]=="Paper"):
16+
print("Player two wins!!")
17+
elif(player_one[play_pos1]=="Paper" and player_two[play_pos2]=="Scissor"):
18+
print("Player two wins!!")
19+
elif(player_one[play_pos1]=="Paper" and player_two[play_pos2]=="Rock"):
20+
print("Player one wins!!")
21+
elif(player_one[play_pos1]=="Scissor" and player_two[play_pos2]=="Rock"):
22+
print("Player two wins!!")
23+
elif(player_one[play_pos1]=="Scissor" and player_two[play_pos2]=="Paper"):
24+
print("Player one wins!!")
25+
26+
# Main Function To Execute Rock Paper Scissor
27+
if __name__ == '__main__':
28+
player_one={0:'Rock',1:'Paper',2:'Scissor'}
29+
player_two={0:'Paper',1:'Rock',2:'Scissor'}
30+
while(1):
31+
num1=input("Player one, Enter your choice ")
32+
num2=input("Player two, Enter your choice ")
33+
bit1=int(input("Player one, Enter the secret bit position "))
34+
bit2=int(input("Player two, Enter the secret bit position "))
35+
rock_paper_scissor(num1,num2,bit1,bit2)
36+
ch=input("Do you want to continue? y/n ")
37+
if(ch=='n'):
38+
break
39+
40+
41+
'''
42+
Output Implementation:
43+
44+
Player one, Enter your choice 123
45+
Player two, Enter your choice 567
46+
Player one, Enter the secret bit position 0
47+
Player two, Enter the secret bit position 1
48+
Draw
49+
50+
Do you want to continue? y/n y
51+
Player one, Enter your choice 012
52+
Player two, Enter your choice 234
53+
Player one, Enter the secret bit position 1
54+
Player two, Enter the secret bit position 2
55+
Player one wins!!
56+
57+
Do you want to continue? y/n y
58+
Player one, Enter your choice 345
59+
Player two, Enter your choice 012
60+
Player one, Enter the secret bit position 0
61+
Player two, Enter the secret bit position 2
62+
Player one wins!!
63+
64+
'''

Basic-Scripts/Simple_calculator.py

+155-29
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,155 @@
1-
operation = input('''
2-
Please type in the math operation you would like to complete:
3-
1 for addition
4-
2 for subtraction
5-
3 for multiplication
6-
4 for division
7-
''')
8-
9-
num = int(input('Enter your first number: '))
10-
num2 = int(input('Enter your second number: '))
11-
12-
if operation == '1':
13-
print('{} + {} = '.format(num, num2))
14-
print(num+num2)
15-
16-
elif operation == '2':
17-
print('{} - {} = '.format(num, num2))
18-
print(num-num2)
19-
20-
elif operation == '3':
21-
print('{} * {} = '.format(num, num2))
22-
print(num*num2)
23-
24-
elif operation == '4':
25-
print('{} / {} = '.format(num, num2))
26-
print(num / num2)
27-
28-
else:
29-
print('Wrong Input! Please Try Again')
1+
operation = input('''
2+
Please type in the math operation you would like to complete:
3+
1 for addition
4+
2 for subtraction
5+
3 for multiplication
6+
4 for division
7+
''')
8+
9+
num = int(input('Enter your first number: '))
10+
num2 = int(input('Enter your second number: '))
11+
12+
if operation == '1':
13+
print('{} + {} = '.format(num, num2))
14+
print(num+num2)
15+
16+
elif operation == '2':
17+
print('{} - {} = '.format(num, num2))
18+
print(num-num2)
19+
20+
elif operation == '3':
21+
print('{} * {} = '.format(num, num2))
22+
print(num*num2)
23+
24+
elif operation == '4':
25+
print('{} / {} = '.format(num, num2))
26+
print(num / num2)
27+
28+
else:
29+
print('Wrong Input! Please Try Again')
30+
=======
31+
32+
33+
"""The previous script becomes very boring for the user as he has to keep on typing just numbers and of wants to interact using
34+
simple english language he is unable to do so. Also the program terminates after one execution and if the user wants to keep on
35+
performing operations it becomes difficult.
36+
I have tried making a more simple and interactive calculator which allows the user to input any statement for performing the tasks. """
37+
38+
39+
40+
41+
def Calculator(num_1,num_2):
42+
#Executing the loop infinite times as we donot know how many times the user will want to run
43+
while(True):
44+
choice= input("Enter what you want to perform: ")
45+
print()
46+
47+
#For Addition user can type any Sentence containing word related to it and will get the output but here we are checking only for the common words
48+
if ("addition" in choice) or ("add" in choice) or ("sum" in choice) or ("plus" in choice):
49+
sum = (num_1) + (num_2)
50+
print("Output....")
51+
print("Adding {} and {} results to {}".format(num_1,num_2,sum))
52+
print()
53+
54+
#For Subtraction user can type any Sentence containing word related to it and will get the output but here we are checking only for the common words
55+
elif ("subtraction" in choice) or ("minus" in choice) or ("difference" in choice) or ("subtract" in choice):
56+
if( num_1 > num_2 ):
57+
diff = (num_1) - (num_2)
58+
print("Output....")
59+
print("Subtracting {} from {} results to {}".format(num_2,num_1,diff))
60+
print()
61+
elif( num_2 > num_1 ):
62+
diff = (num_2) - (num_1)
63+
print("Output....")
64+
print("Subtracting {} from {} results to {}".format(num_1,num_2,diff))
65+
print()
66+
67+
#For Multiplication user can type any Sentence cpntaining word related to it and will get the output but here we are checking only for the common words
68+
elif ("multiplication" in choice) or ("product" in choice) or ("multiply" in choice):
69+
if(num_1==0 or num_2==0):
70+
print("Output....")
71+
print("Multiplying {} and {} results to 0".format(num_1,num_2))
72+
print()
73+
elif(num_1==1):
74+
print("Output....")
75+
print("Multiplying {} and {} results to {}".format(num_1,num_2,num_2))
76+
print()
77+
elif(num_2==1):
78+
print("Output....")
79+
print("Multiplying {} and {} results to {}".format(num_1,num_2,num_1))
80+
print()
81+
else:
82+
mul = (num_1) * (num_2)
83+
print("Output....")
84+
print("Multiplying {} and {} results to {}".format(num_1,num_2,mul))
85+
print()
86+
87+
#For Division user can type any Sentence cpntaining word related to it and will get the output but here we are checking only for the common words
88+
elif("division" in choice) or ("divide" in choice) or ("quotient" in choice):
89+
if( num_1 > num_2 ):
90+
if(num_2==0):
91+
print("Output....")
92+
print("Error: Please try with some other values!")
93+
94+
elif(num_1==0):
95+
print("Output....")
96+
print("Dividing {} from {} results to 0".format(num_1,num_2))
97+
print()
98+
else:
99+
div = (num_1) / (num_2)
100+
print("Output....")
101+
print("Dividing {} from {} results to {}".format(num_1,num_2,div))
102+
print()
103+
elif(num_1==0 and num_2==0):
104+
print("Infinity!")
105+
print()
106+
elif( num_2 > num_1 ):
107+
if(num_1==0):
108+
print("Output....")
109+
print("Error: Please try with some other values!")
110+
print()
111+
112+
elif(num_2==0):
113+
print("Output....")
114+
print("Dividing {} from {} results to 0".format(num_1,num_2))
115+
print()
116+
else:
117+
div = (num_2) / (num_1)
118+
print("Output....")
119+
print("Dividing {} from {} results to {}".format(num_2,num_1,div))
120+
print()
121+
122+
#For exiting the loop user can type any Sentence containing word related to it and it will exit from the loop but here we are checking for the common words
123+
elif ("exit" in choice) or ("stop" in choice) or ("return" in choice):
124+
break
125+
126+
else:
127+
print()
128+
print("Operation not found: Please try again!")
129+
print()
130+
131+
132+
133+
def main():
134+
135+
print()
136+
print(" THIS IS A BASIC USER FRIENDLY CALCULATOR! ")
137+
print()
138+
print("You can type a sentence and interact.")
139+
print()
140+
#inputting two numbers at a time using the split function
141+
num_1,num_2 = input("Enter two numbers: ").split()
142+
num1=float(num_1)
143+
num2=float(num_2)
144+
145+
146+
#printing both the numbers
147+
print("Number 1 is: ",num_1)
148+
print("Number 2 is: ",num_2)
149+
print()
150+
151+
Calculator(num_1,num_2)
152+
153+
154+
if __name__ == "__main__":
155+
main()

0 commit comments

Comments
 (0)