Skip to content

Commit 5c28dd8

Browse files
committed
leet
1 parent 0f8b1ad commit 5c28dd8

File tree

348 files changed

+18852
-0
lines changed

Some content is hidden

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

348 files changed

+18852
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import random
2+
3+
4+
inside = random.randint(1,37890) # choses a random integer between given range
5+
print(inside)
6+
7+
outside = random.randrange(1,1000) # choses a random number number in given range
8+
print(outside)
9+
10+
colors = ['green','black','blue','yellow','white']
11+
print(random.choice(colors)) # choses random element from list
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Morgans Formula In Algebra Set operations
2+
# number(set A) + number(set B) - number(set A interaction B)
3+
# n(a)+ n(b) - n(anb)
4+
# you can add sets or increase the number elements of sets The formula still works
5+
6+
a = { 1 , 23 , 55 , 76 , 13 , 90 , 34 , 78 }
7+
b = { 12 , 345 , 8 , 4 , 0 , 7 , 4 , 3 , 53 , 4 , 6 , 3 }
8+
9+
abInteraction = a & b # & operator interacts two sets
10+
abUnion = a | b # | operator makes union of two sets
11+
12+
eqn = len(a) + len(b) - len(abInteraction)
13+
print(str(eqn) + ' = ' + str(len(abUnion)))
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Prime number Determiner
2+
# replace input() with raw_input() in Python version 2.7 input() works with version 3
3+
import math as Math
4+
5+
POSITIVE_MESSAGE = " is a prime number"
6+
NEGATIVE_MESSAGE = " is not a prime number"
7+
8+
9+
def is_number_prime(number):
10+
"""
11+
Function which checks whether the number is a prime number or not
12+
:param number: integer - to be checked for prime-ness
13+
:return: boolean - true if prime, else false
14+
"""
15+
16+
"""
17+
This is the main logic behind reducing the numbers to check for as factors
18+
if N = a * b; where a<=b and a,b C (1, N)
19+
then, a * b >= a*a;
20+
which leads to => a*a <= N
21+
=> a <= sqrt(N)
22+
Hence checking only till the square root of N
23+
"""
24+
upper_lim = Math.floor(Math.sqrt(number)) + 1
25+
is_prime = True if number != 1 else False
26+
27+
for i in range(2, upper_lim):
28+
if number % i == 0:
29+
is_prime = False
30+
break
31+
# The moment there is a divisor of 'number', break the iteration, as the number is not prime
32+
33+
return is_prime
34+
35+
36+
while True:
37+
startOrEnd = str(input('Start or End : '))
38+
if startOrEnd == 'Start':
39+
number = int(input('Number to Check : '))
40+
result = str(number)
41+
prime_status = is_number_prime(number)
42+
43+
if prime_status:
44+
result += POSITIVE_MESSAGE
45+
else:
46+
result += NEGATIVE_MESSAGE
47+
print(result)
48+
else:
49+
print('Program Ended...')
50+
break
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# pre code
2+
# main list of contacts
3+
contacts = {}
4+
5+
# funcs of pre code
6+
# func to add new contact
7+
def newContact():
8+
while True:
9+
newContact = raw_input("Name for new Contact : ")
10+
numForNewContact = raw_input("Number for Contact : ")
11+
add = raw_input("Add or Try again :")
12+
if add.strip() == "Add":
13+
contacts[newContact] = numForNewContact
14+
print("Contact Successfully added.")
15+
break
16+
elif add.strip() == "Try again":
17+
continue
18+
else :
19+
print("Invalid Input.try again")
20+
continue
21+
startAgain = raw_input("Add more or continue : ")
22+
if startAgain.strip() == "Add more":
23+
print(" ")
24+
continue
25+
elif startAgain.strip() == "continue":
26+
print(" ")
27+
break
28+
29+
# func to search for a contact
30+
def searchContact():
31+
while True:
32+
search = raw_input("Search for contact : ")
33+
toShow = str(search) + contacts[search]
34+
print(toShow)
35+
startAgain = raw_input("Search more or continue : ")
36+
if startAgain.strip() == "Search more":
37+
print(" ")
38+
continue
39+
elif startAgain.strip() == "continue":
40+
print(" ")
41+
break
42+
43+
# func to edit a contact
44+
def editContact():
45+
while True:
46+
whichToEdit = raw_input("Name of Contact of which Number to Edit : ")
47+
contacts[whichToEdit] = raw_input("Number to add : ")
48+
startAgain = raw_input("Edit more or continue : ")
49+
if startAgain.strip() == "Edit more":
50+
print(" ")
51+
continue
52+
elif startAgain.strip() == "continue":
53+
print(" ")
54+
break
55+
56+
# main code to interact
57+
while True:
58+
print("hello,".title())
59+
# part of main code to start or end
60+
startOrEnd = raw_input("Start or End : ")
61+
if startOrEnd.strip() == "Start":
62+
# part of main code to control functions
63+
addSearchEdit = raw_input("Add or Search or Edit : ")
64+
if addSearchEdit.strip() == "Add":
65+
print(newContact())
66+
elif addSearchEdit.strip() == "Search":
67+
print(searchContact())
68+
elif addSearchEdit.strip() == "Edit":
69+
print(editContact())
70+
else :
71+
print("Invalid Input . Try Again")
72+
continue
73+
elif startOrEnd.strip() == "End":
74+
print("Ending...")
75+
break
76+
else :
77+
print("Invalid Input . Try Again")
78+
continue
79+
# part of main code to start again or end
80+
startAgain = raw_input("Start again or End : ")
81+
if startAgain.strip() == "Start again":
82+
print("Starting again...")
83+
continue
84+
elif startAgain.strip() == "End":
85+
print("Ending program...")
86+
break
87+
else :
88+
break
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This example shows you string operations
2+
3+
name = 'Kalpak'
4+
print('My name is ' + name) # I have given space after is notice
5+
6+
age = 14
7+
print('My age is ', age) # comma seprates two different things you want to print
8+
9+
print('This isn\'t going away too soon.') # that \ is called as an escape character
10+
# the \ is used to use same quote in a string
11+
12+
print('I love newlines \n') # \n prints new line after string or according to its position
13+
14+
print('\t I love tabs') # \t adds a tab according to its position
15+
16+
multiple = 'Iron Man'
17+
print(multiple * 5) # this will print string 5 times
18+
19+
# string methods in built
20+
country = 'Norway'
21+
print(country.upper()) # prints all letters in upper case
22+
print(country.lower()) # prints all letters in lower case
23+
print(country.title()) # converts into title
24+
25+
# string formatting
26+
print('%s %s %s'%('I' , 'am' , 'cool'))
27+
28+
expression = 'I love'
29+
movie = 'Captain America 3'
30+
print('%s %s'%(expression , movie))
31+
32+
# type conversion
33+
addition = 12343 + 3349
34+
print('The answer is ' + str(addition)) # str() method converts non-string into string
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# list operations part 2
2+
3+
siliconValley = ['Google','Apple','Dropbox','Facebook','Cisco','Adobe','Oracle','Samsung']
4+
print(siliconValley)
5+
6+
# hmm seems like i forgot to add Electronic Arts in the list siliconValley
7+
# This will add the element at the end of the list
8+
siliconValley.append('Electronic Arts')
9+
print(siliconValley)
10+
11+
# thats cool but I want my element at specific position
12+
siliconValley.insert(5, 'AMD')
13+
# 5 is the position and whatever you add after comma is element
14+
15+
# Okay enough I want to pop out an element from list and I want to use it in a string
16+
# you have to provide the index of elementyou want to pop out
17+
poppedElement = siliconValley.pop(4)
18+
print('Popped element is ' + poppedElement)
19+
20+
# Oops I Samsung isnt in silicon valley, I have to remove Samsung from list
21+
# How am I gonna do thats
22+
# You have to enter the element in parenthesis and not it's index
23+
siliconValley.remove('Samsung')
24+
print(siliconValley)
25+
26+
# I want to sort the list in alphabetical order
27+
# How to do thats
28+
# simple
29+
siliconValley.sort()
30+
# or
31+
sorted(siliconValley)
32+
print(siliconValley)
33+
34+
# I wanted list in reverse alphabetical order
35+
# simple
36+
siliconValley.sort(reverse = True)
37+
# or
38+
sorted(siliconValley , reverse = True) # seperate the reverse with comma
39+
print(siliconValley)
40+
41+
# Okay what if i dont know about the index of an element but i want to print only that element
42+
googleIndex = siliconValley.index('Google')
43+
print(siliconValley[googleIndex])
44+
45+
# I am tired of watching those elements again and again
46+
# How I am going to do thats
47+
# easy
48+
del siliconValley
49+
print(siliconValley) # this should probably give you an NameError
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def iLoveDiscount(discount , mp): # mp is market price
2+
discountPerc = discount / mp * 100
3+
return('Discount is ' + str(discountPerc) + '%')
4+
5+
print('Hello\n')
6+
print('Press Enter to exit')
7+
while(True): # I've put counting discount in a loop cause if you want to count on multiple items
8+
more = str(input('Count or End : '))
9+
if more == 'Count':
10+
disCount = float(input('Discount : '))
11+
marketPrice = float(input('Market Price : '))
12+
print(iLoveDiscount(disCount , marketPrice))
13+
continue
14+
else:
15+
quit()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="generator" content="pandoc" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7+
<title>README</title>
8+
<style type="text/css">
9+
code{white-space: pre-wrap;}
10+
span.smallcaps{font-variant: small-caps;}
11+
span.underline{text-decoration: underline;}
12+
div.column{display: inline-block; vertical-align: top; width: 50%;}
13+
</style>
14+
</head>
15+
<body>
16+
<h1 id="beginners-python-programs">Beginners-Python-Programs</h1>
17+
<p>Basic python CLI programs as examples<br> All the examples are useful examples<br> These examples are of beginners’ level<br> <br> Hey guys I wrote these programs when I was just starting up with programming, now I realize that many of ’em feel very un-professional and useless so I decided to go one by one through all and make ’em more useful and professional ! <br></p>
18+
<p>Note: In 2.x versions input isn’t useful , lly , in 3.x versions raw_input isn’t useful. Also, xrange() and other methods are discontinued or changed in 3.x versions of python. Change the keywords accordingly!</p>
19+
<pre>
20+
<strong>NOTE: WORK IN PROGRESS!
21+
Files Outside Particular Folders/Directories have not been checked yet!
22+
Files inside, directories offer much elegant code and explaination
23+
</strong>
24+
</pre>
25+
<p><br><br> Also see this : Beginners-Python-Examples/CONTRIBUTING.md<br> contact [email protected]</p>
26+
</body>
27+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Beginners-Python-Programs
2+
Basic python CLI programs as examples<br>
3+
All the examples are useful examples<br>
4+
These examples are of beginners' level<br>
5+
<br>
6+
Hey guys I wrote these programs when I was just starting up with programming, now I realize that many of 'em feel very un-professional and useless so I decided to go one by one through all and make 'em more useful and professional !
7+
<br>
8+
9+
Note: In 2.x versions input isn't useful , lly , in 3.x versions raw_input isn't useful. Also, xrange() and other methods are discontinued or changed in 3.x versions of python. Change the keywords accordingly!
10+
11+
<pre>
12+
<strong>NOTE: WORK IN PROGRESS!
13+
Files Outside Particular Folders/Directories have not been checked yet!
14+
Files inside, directories offer much elegant code and explaination
15+
</strong>
16+
</pre>
17+
<br><br>
18+
Also see this : Beginners-Python-Examples/CONTRIBUTING.md<br>
19+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
import turtle
3+
t = turtle.Pen()
4+
5+
for i in range(150):
6+
t.color(random.choice(['green','red','violet']))
7+
t.width(5)
8+
t.forward(i)
9+
t.right(30)

0 commit comments

Comments
 (0)