<repo_name>malikxomer/static<file_sep>/6.Project one-Circle of Squares/1.Circle of Squares(My Logic).py
import turtle
my_turtle = turtle.Turtle()
my_turtle.speed(0)

def fun(length,angle,angle2):
    my_turtle.forward(length)
    my_turtle.right(angle)
    my_turtle.forward(length)
    my_turtle.right(angle)
    my_turtle.forward(length)
    my_turtle.right(angle)
    my_turtle.forward(length)
    my_turtle.right(angle2)

for square in range(100): #360/11 = ... # we choose a prime number so the circle is dense 
    fun(100,90, 101)

<file_sep>/10.Excersices/10.Rock paper scissor solution by Qazi.py
import random

COMPUTER_SCORE = 0
HUMAN_SCORE = 0
human_choice = ""
computer_choice = ""

def choice_to_number(choice):
    """Convert Choice to number."""
    my_dict = {'rock':0 , 'paper':1 , 'scissors':2}
    return my_dict[choice]

def number_to_choice(number):
    my_dict = {0:'rock' , 1:'paper' , 2:'scissors'}
    return my_dict[number]

def random_computer_choice():
    """Choose randomly for computer"""
    random.choice(['rock' , 'paper' , 'scissors'])

def choice_result(human_choice,computer_choice):
    """Return the result of who wins"""
    global COMPUTER_SCORE
    global HUMAN_SCORE

    human_number = choice_to_number(human_choice)
    computer_choice = choice_to_number(computer_choice)

# Anything % 3 == a number between 0-2
# [0,1,2]  == [rock, paper, scissors]
# rocks vs scissors
# (0-2) % 3 == 1
# (-2) % 3 == 1
# 1 == 1
# rock wins
#
#paper vs scissors
# (paper - scissors) % 3 == 1
# (1-2) % 3 == 1
# 2 == 1
# scissors wins
#
# paper vs rocks
# (paper - rocks) % 3 == 1
# (1-0) % 3 == 1
# 1 %3 == 1
# 1 == 1
# paper wins
    if (human_number - computer_number) % 3 == 1:
        COMPUTER_SCORE +=1
    elif human_number == computer_number:
        print('Tie')
    else:
        HUMAN_SCORE +=1


###############################
def test_number_to_choice():
    assert number_to_choice(0) == 'rock'
    assert number_to_choice(1) == 'paper'
    assert number_to_choice(2) == 'scissors'

def test_choice_to_number():
    assert choice_to_number('rock') == 0
    assert choice_to_number('paper') == 1
    assert choice_to_number('scissors') == 2

def test_all():
    test_choice_to_number()
    test_number_to_choice()

#Uncomment the line below to test your code
test_all()

<file_sep>/10.Excersices/2.Square of number.py
def square_number(number):
#    return number*number
    return number ** 2 # **2 is used to get square of a number
print(square_number(3))
assert square_number(0) == 0 #To check the answer is true or false
assert square_number(1) == 1 #To check the answer is true or false
assert square_number(2) == 4 #To check the answer is true or false
assert square_number(3) == 9 #To check the answer is true or false
assert square_number(4) == 16 #To check the answer is true or false
assert square_number(5) == 25 #To check the answer is true or false
assert square_number(6) == 36 #To check the answer is true or false
assert square_number(7) == 49 #To check the answer is true or false
assert square_number(8) == 64 #To check the answer is true or false
assert square_number(9) == 81 #To check the answer is true or false
assert square_number(10) == 100 #To check the answer is true or false

<file_sep>/9.Loops/1.For Loops.py
#Do something 5 times
for i in range(5):  
    print(i)

print(list(range(5)))   #show what is the range of 5 --> [0,1,2,3,4]

#Range takes starting and ending point, excluding the ending point
#range(Start,Stop)
list(range(0,2)) #gives back [0,1]

for number in range(20,41):
    print(number)

#Add numbers in a range
    #Range(1,4) contains [1,2,3]
    #We have to add 1+2+3 and return a 6

count = 0
for number in range(1,4):
    count = count+number
print(count)


#Write a function that sums all elements of a list and return them
def sum_list(my_list):
    count=0
    for number in my_list:
        count = count+number
    return count
#assert gives us an error if statement is false, and nothing if it is true
assert sum_list([1,2,3]) == 6
assert sum_list([1,2,3,4])==10

    
<file_sep>/8.Boolean Algebra/1.Boolean Algebra.py
# If condition
# Generates true or False as a result i-e
if True:
    print('Hello')
if False:
    print('hi')

# == equals
# < Smaller than
# > Greater than
# <= Smaller than or equals
# >= Greater than or equals
# Not equals !=

johnny_hours_worked = 40
if johnny_hours_worked >40:
    print('pay him overtime')

johnny_hours_worked = 41
if johnny_hours_worked >40:
    print('pay him overtime now')
<file_sep>/7.Dictionaries/1.Dictionary Basics.py
#dictionay is made up of to things i-e key and value
# In java we call them maps of graphs
#Dictionay[key] --> value
# dictionart = {'name':'Omer' , 'Age':'24'}
#1 : Simple Dictionary ==
phone_book = {
    'omer' : '000-123-456-789',
    'Basil' : '111-123-456-789',
    'Iftikhar' : '222-123-456-789'
              }
print(phone_book['omer'])

#2 : Dictionary keys containing Lists ==
#Each key contains multiple values
phone_book = {
    'omer' : ['000-111-222-333','<EMAIL>','Rawalpindi'],
    'basil' : ['666-777-888-999','<EMAIL>','Gujrat'],
    'iftikhar' : ['555-555-666-555','<EMAIL>','Peshawar']
              }
print(phone_book['omer'][1])
<file_sep>/2.loops/for loop.py
import turtle

my_turtle=turtle.Turtle()

def square(length,angle):
	my_turtle.forward(length)
	my_turtle.left(angle)
	my_turtle.forward(length)
	my_turtle.left(angle)
	my_turtle.forward(length)
	my_turtle.left(angle)
	my_turtle.forward(length)

for i in range(4):
        square(50,90)


	
<file_sep>/10.Excersices/3.Check is Even.py
def check_even(number):
    if number%2 == 0:
        return print('number is even')
    elif number%2 != 0:
        return print('number is odd')
check_even(13)
<file_sep>/10.Excersices/4.Length of a string.py
#My way:
def string_length(Str):
    return len(Str)
print(string_length('<NAME>'))

#Qazi's way:

def string_len(my_string):
    count=0
    for letter in my_string:
        #print(letter)
        count+=1
    return count

print(string_len('hello'))

<file_sep>/10.Excersices/9.Rock Paper Scissors(my way).py
#Rules for the game
# rock vs rock == draw
# rock vs paper == paper wins
# rock vs scissor == rock wins

# paper vs paper == draw
# paper vs rock == paper wins
# paper vs scissors == scissors wins

# scissors vs scissors == draw
# scissors vs paper == scissors wins
# scissors vs rock == rock wins

import random

#Global variable thal all function know about.
#DO NOT EDIT THESE GLOBAL VARIABLES
#OR YOUR GAME WILL BREAK

COMPUTER_SCORE = 0
HUMAN_SCORE = 0
human_choice = ""
computer_choice = ""

def choice_to_number(choice):
    """Convert Choice to number."""
    #If choice is rock, give back 0
    #If choice is paper, give back 1
    #If choice is scissors, give back 2
    return {'rock':0 , 'paper':1 , 'scissors':2}[choice]

def number_to_choice(number):
    """Convert Number to choice."""
    #If choice is 0, give back rock
    #If choice is 1, give back paper
    #If choice is 2, give back scissors
    return {0:'rock' , 1:'paper' , 2:'scissors'}[number]

def random_computer_choice():
    """Choose randomly for computer"""
    #lookup random.choice()
    choice = random.randint(0,2)
    return number_to_choice(choice)
# or we can use return random.choice(['rock' , 'paper' , 'scissors'])

def choice_result(human_choice,computer_choice):
    """Return the result of who wins"""
    #DO NOT REMOVE THESE GLOBAL VARIABLE LINES.
    #we specified them to say that we want the variables in the main program to change their values
    global COMPUTER_SCORE
    global HUMAN_SCORE
    
    # based on the given human_choice and computer_choice
    # determine who won and increment their score by 1.
    # if tie, then don't increment anyone's score

    #example code
    # if human_choice == 'rock' and computer_choice == 'paper':
    #       COMPUTER_SCORE = COMPUTER_SCORE +1
    
    if human_choice == 'rock' and computer_choice == 'paper':
        COMPUTER_SCORE = COMPUTER_SCORE +1
        return COMPUTER_SCORE
    elif human_choice == 'rock' and computer_choice == 'scissors':
        HUMAN_SCORE = HUMAN_SCORE+1
        return HUMAN_SCORE
    elif human_choice == 'rock' and computer_choice == 'rock':
        return 'same'
        
    elif human_choice == 'paper' and computer_choice == 'rock':
        HUMAN_SCORE = HUMAN_SCORE+1
        return HUMAN_SCORE
    elif human_choice == 'paper' and computer_choice == 'scissors':
        COMPUTER_SCORE = COMPUTER_SCORE +1
        return COMPUTER_SCORE
    elif human_choice == 'paper' and computer_choice == 'paper':
        return 'same'
        
    elif human_choice == 'scissors' and computer_choice == 'paper':
        HUMAN_SCORE = HUMAN_SCORE+1
        return HUMAN_SCORE
    elif human_choice == 'scissors' and computer_choice == 'rock':
        COMPUTER_SCORE = COMPUTER_SCORE +1
        return COMPUTER_SCORE
    elif human_choice == 'scissors' and computer_choice == 'scissors':
        return 'same'
    else:
        print('Hello')
      

###############################
#DO NOT REMOVE THESE TEST FUNCTIONS.
#THEY WILL TEST YOUR CODE
def test_number_to_choice():
    assert number_to_choice(0) == 'rock'
    assert number_to_choice(1) == 'paper'
    assert number_to_choice(2) == 'scissors'

def test_choice_to_number():
    assert choice_to_number('rock') == 0
    assert choice_to_number('paper') == 1
    assert choice_to_number('scissors') == 2

def test_all():
    test_choice_to_number()
    test_number_to_choice()

#Uncomment the line below to test your code
test_all()

###############################
human_choice = number_to_choice(1)
computer_choice = random_computer_choice()
choice_result(human_choice,computer_choice)

print("computer score == ",COMPUTER_SCORE)
print("human score == ",HUMAN_SCORE)
print('human choice == ',human_choice)
print("random computer choice == ",computer_choice)
<file_sep>/8.Boolean Algebra/2.Logical operators.py
#AND operator
5 and 5     #True
True and True   #True
True and False  #False

johnny_homework=True
throw_out_garbage=True
if johnny_homework and throw_out_garbage: #Returns true
    print('hello')

#OR operator
poison = False
pizza = True
pizza or poison     #True

#NOT operator
not False   #True
not True    #False
not(True or False)  #False


<file_sep>/5.Lists/2.Slicing in List.py
# Slicing in Lists
# We are going to slice elements of a String
# They will be stored in a List of Strings

'what-is-going-on'.split()
greetings = 'what-is-going-on'.split('-')
greetings
greetings[0]
greetings[1]
greetings[2]
greetings[3]
greetings[-1]
greetings[-2]
greetings[-3]

# We can also do slicing like in Strings using [Start: Stop: Step]
race = ['john','bob','timothy']
race[0:]
race[:]
race[0:2]
race[0:-1]
race[0:-1]
<file_sep>/4.String_Slicing/1.stringSlicing.py
#Gets the first letter of hello, which is 'h'
'hello'[0]

#[Start:Stop]
'hello'[0:4]

#we can skip the start, if it is zero
'hello'[:3]

#if we skip the stop,it will take the last index
'hello'[0:]

#if we skip start and stop it will go from 0 to last index i-e this [:] will be [0:last index]
'hello'[:]

# [-1] will show the last index i-e 'o'
'hello'[-1]

#All of the below do the same task and delete the last 'o' from hello
'hello'[0:-1]
'hello'[0:4]
'hello'[:4]
'hello'[:-1]



<file_sep>/4.String_Slicing/4.Reverse a string.py
# By using string slicing
data = "atoyot"
stringlength = len(data)   # calculates length of string
slicedstring = data[stringlength::-1]    # Reverse the String
print (slicedstring)     # Print the string



# By Using a loop, Returns the string in the form of a list
data = "ikuzus"
reversedString = []
index = len(data)     # Calculate length of string and save in index
while index> 0:
    reversedString += data[index-1]    #save the value of data[index-1] in reverseString
    index = index - 1
print(reversedString)



# By using join condition
data = 'adnoH' #initial string
reversed=''.join(reversed(data))    # .join() method merges all of the characters resulting from the reversed iteration into a new string
print(reversed)      #print the reversed string

<file_sep>/4.String_Slicing/3.startstopstep.py
#start:stop:step
#step is used to jump the object
greeting = 'Hi how are you doing, it is very nice to meet you.'
greeting
greeting[0:-1:1]
#step=1 is by default so it won't affect the text
greeting[0:-1:2]
greeting[0:-1:3]


<file_sep>/10.Excersices/11.Square a list.py
numbers = [1,2,3,4,5,6,7,8,9]

squared_numbers = []

for number in numbers:
    squared_numbers.append(number ** 2)

print(squared_numbers)
<file_sep>/9.Loops/2.while loops.py
# We use while loops when we don't know when it is going to stop
# We use for loops when we know when it is going to stop
#   While ( CONDITION )  -->  True
#       THEN THIS
# Condtion example:
#       5<6 --> True, so the loop will run
#       5>6 --> False, so the loop won't run

count = 0
while count < 100:
    print(count)
    count=count+1
#    if count == 70:
#       break

# ============= Practice =============
# Print from 100 to 1 and instead of zero print 'blast off'
count = 100
while count>0:
    print(count)
    count=count-1
    if count==0:
        print('blast off')
<file_sep>/5.Lists/5.Using Append method to add.py
# You can use Append on List
# Append makes the Lists more powerful and awesome

numbers = [1,2,3,4,5]
# Append is used to add something at the end of list
numbers.append(6)
numbers.append(7)

# we can add by using a for loop , numbers from 8 to 20
list(range(8,21)) #checking the numbers in this range

for number in range(8,21):
    numbers.append(number)

#Reverse
number[::-1]

    
<file_sep>/5.Lists/4.Xbox example using split.py

data = 'XBOX 360 | 150 | NEW'
details = data.split('|')
print(details)
product_name=details[0]
product_price=details[1]
product_condition=details[2]
print(product_name)
print(product_price)
print(product_condition)

#Easiest way of doing the same
product,price,condition = data.split('|')
print(product)
print(price)
print(condition)
<file_sep>/10.Excersices/1.Sum two numbers.py
def sum_numbers(number1,number2):
    return number1+number2
print(sum_numbers(2,3))

    
<file_sep>/5.Lists/3.Reversing a List Using Split.py
#We will use slicing to reverse a list here
race = ['john','bob','timothy']
race[0:] # will give us the whole list
race[::-1] #It will REVERSE the string

data =  [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
data[::-1]

<file_sep>/10.Excersices/7.Find the bigger guy from three.py
# My solution
def find_max(num1,num2,num3):
    if num1>num2:
        if num1>3:
            return num1
        elif num1<num3:
            return num3
        else:
            return 'num1 and num3 are equal'
    elif num2>num1:
        if num2>num3:
            return num2
        elif num2<num3:
            return num3
        else:
            return 'num2 and num3 are equal'
    else:
        return 'All numbers are equal'
print(find_max(8,8,8))

#######################
# Qazi's solution
def find_bigger(guy1,guy2,guy3):
    if guy1>guy2:
        bigger_guy = guy1
    else:
        bigger_guy = guy2

    if bigger_guy > guy3:
        biggest_guy=bigger_guy
    else:
        biggest_guy=guy3
    return biggest_guy
    
print(find_bigger(16,234,111))

##########################
# One line solution
def bigger_guy(num1,num2):
    if num1>num2:
        return num1
    else:
        return num2

def biggest_guy(num1,num2,num3):
    return bigger_guy(bigger_guy(num1,num2),num3)

print(biggest_guy(50,40,30))

#########################
#Python built in function
def big_num(number1,number2,number3,number4):
    return max(number1,number2,number3,number4)
print(max(30,10,40,20))
<file_sep>/10.Excersices/5.last letter of a string.py
def last_letter(my_string):
    return my_string[-1]
print(last_letter('omer!'))
<file_sep>/3.primitive data types/Primitive_datatypes.py
#string data types
'hello'
"hello"

#Integers
3
4
5

#float
40.22234
2.46345
1234.12341

<file_sep>/10.Excersices/6.Find the bigger guy from two.py
def find_max(num1,num2):
    if num1>num2:
        return num1
    elif num2>num1:
        return num2
    else:
        return 'both numbers are equal'
print(find_max(3,6))
<file_sep>/1.functions/function.py
import turtle

my_turtle=turtle.Turtle()

def square():
	my_turtle.forward(100)
	my_turtle.left(90)
	my_turtle.forward(100)
	my_turtle.left(90)
	my_turtle.forward(100)
	my_turtle.left(90)
	my_turtle.forward(100)

square()

	
<file_sep>/11.Tuples/Tuples.py
#Lists
groceries = ['banana' , 'apple', 'grapes']

#Tuples
#We cant change things in a tuple, no adding, no deleting
social_security_number = ('12345','12345','12346234')

groceries.append('cheese')
print(groceries)

#We can't do the above operations to a Tuple
# It is used in cases where you need data to never be changed
<file_sep>/10.Excersices/8.Usain Bolt races me and a guy.py
# give choice to get back a name
def number_to_choice(choice):
    if choice==1:
        return 'Usain'
    elif choice==2:
        return 'Me'
    elif choice==3:
        return 'Qazi'
    else:
        return 'Not a member of race'

# give name to get back a position

def choice_to_number(choice):
    if choice=='Usain':
        return 1
    elif choice=='Me':
        return 2
    elif choice=='Qazi':
        return 3
    else:
        return 'Not a member of race'

print(number_to_choice(2))
print(choice_to_number('Qazi'))

##########################
#Using dictionary to solve the same problem

def num_to_choice(number):
    return {1:'Usain',2:'Me',3:'Qazi'}[number]

def choice_to_num(name):
    return {'Usain':1,'Me':2,'Qazi':3}[name]
print(num_to_choice(3))
print(choice_to_num('Usain'))    
<file_sep>/8.Boolean Algebra/3.if-else-elseif.py
#if
#else
#else if or elif in python
#Rock paper Scissors--> Rock wins in this game

human = 'rock'
computer = 'scissors'
if human == 'rock' and computer == 'scissors':
    human_score = 1


# Now checking with else if
computer = 'banana'
if human == 'rock' and computer == 'scissors':
    human_score = 1
elif human == 'rock' and computer == 'banana':
    computer_score=0
    human_score=0
    print('you cant pick anything other than rock and scissors')

# Checking if anyone picked wrong
if human == 'banana' or computer == 'banana':
    print('wrong input')

#Checking by other way
if computer != 'rock' or computer !='scissors' or computer !='paper':
    print("WRONG CHOICE,PICK AGAIN")



<file_sep>/5.Lists/1.Creating Lists and accessing index.py
# Creating a list of different data types
things = ['apple','banana',4,5,'oranges']
things
things[0]
things[1]
things[2]
things[3]
things[4]
things[-1]
things[-2]
things[-3]
things[-4]

<file_sep>/4.String_Slicing/2.stringSlicingOnRealData.py
#index('|') is used to get the index number of '|'
# First Way: This is manual and not good for too much data i-e spread sheet
data = 'XBOX 360 | 150 | New'
product_name = data[:data.index('|')]
product_price = data[11:15]
product_condition = data[16:]
print("product name = "+product_name)
print("product price = "+product_price)
print("product condition ="+product_condition)

# Second way: But this is too length so we have a third way
data = 'XBOX 360 | 150 | New'
product_name = data[:data.index('|')]
print("product name = "+product_name)

new_data = data[data.index('|')+1:]
product_price = new_data[:new_data.index('|')]
print("product price = "+product_price)

product_condition = new_data[new_data.index('|')+1:]
print("product condition ="+product_condition)

#Third way: By using find(), it is short and fast
data = 'XBOX 360 | 150 | New'
product_name_index = data.find('|')
product_name = data[:product_name_index]
print("product name = "+product_name)

#start finding for '|' and starts from index 10 i-e product_name_index+1
product_price_index = data.find('|',product_name_index+1)
product_price = data[product_name_index+1:product_price_index]
print("product price = "+product_price)

#start finding for '|' and starts from index 16 i-e product_price_index+1
product_condition = data[product_price_index+1:]
print("product condition ="+product_condition)



# WE CAN DIRECTLY FIND FROM PIPE TO PIPE I-E ('|') TO ('|')
product_price = data[data.find('|')+1 : data.find('|',10)]
print(product_price)
