Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

python

# Hello World program in Python
import hashlib

hash_string = "somestring\n"
hash = hashlib.sha1()
hash.update(hash_string.encode('utf-8'))    
print (hash.hexdigest());

Chocolate_Bars_for_Kata_001

# 4 oz and 1.5 oz
# 50% chocolate, 25% nuts and 25% raisins.

# Note: All ingredients quantities are in ounces.
#
# Use 50% of the incoming ingredients deliveries to make 4 oz bars,
# and 50% to make 1.5 oz bars.
# Whatever remains from that day moves into storage for the next day.

# There may be some inventory (in ounces) already in an incoming dictionary:

#     storage = {
#        "choco": 25, 
#        "nuts": 30,
#        "raisins": 10
#        }

# Use everything there first for big bars only (4 oz).
# If there is anything left over, make small bars (1.5 oz). 
# The rest should just stay in storage.
# Then take the 50%/50% of the incoming ingredients and make what you can. 
# Put what's left from the daily 50%/50% production into storage.


# Input:
# A dictionary of previous inventory.
# A list with sub lists for the daily deliveries.

# Process:
# Each day:
# Use inventory for big bars.
# Use leftover inventory for small bars.
# (Leave the rest in storage.)
# Split the incoming ingredients 50/50.
# Make big and small bars with incoming ingredients.
# Put the remaining imcoming ingredients into storage.


# Output:
# Return a list with two items:
# The number of big bars made and the number of small bars made.


import math

def make_bars(storage, lst):
    '''
    stoarge = {
        "choco": 25, 
        "nuts": 30,
        "raisins": 10
    }
    '''
    
    bars_split = {
        "choco": 0, 
        "nuts": 0,
        "raisins": 0
    }
    

    final_bars = {
        "big": 0,
        "small": 0
    }


    # Make what you can from inventory:
    # All the big bars possible.
    # Then, all the small bars possible.
    for i in storage:
        print(i, storage[i])
    
    print()

    # Find out how many big bars can be made from what is in inventory.
    
    # choc: 50%, nuts: 25%, raisins: 25%

    # Use whichever is smaller: chocolate, nuts or raisins.

    sm = 10000
    sm_name = "nothing yet"
    
    for i in storage:
        if storage[i] < sm:
            sm = storage[i]
            sm_name = i
    
    print(sm_name)
    print(sm)
    print()
    
    
    # If the smallest is chocolate, 
    # check to see if 1/2 the amount is in both
    # nuts and raisins.
    # If no, adjust the amount for nuts/raisins.
    #
    # If nuts or raisins are the smallest,
    # check to see if twice the amount is in chocolate.
    # If no, adjust for chocolate.
    
    
    
    
    
    for i in lst:
        print(i)

        


print(make_bars(
    {
        "choco": 50, 
        "nuts": 30,
        "raisins": 10
    }, 
    [
        [100, 70, 40],
        [200, 20, 30],
        [150, 100, 120],
        [300, 150, 100],
        [50, 10, 20]
]))





# bottom of screen

Deep Learning in Python-Chapter 2

# =============================================================================
# The need for optimization
# =============================================================================

''' Scaling up to multiple data points '''

from sklearn.metrics import mean_squared_error

# Create model_output_0 
model_output_0 = []
# Create model_output_1
model_output_1 = []

# Loop over input_data
for row in input_data:
    # Append prediction to model_output_0
    model_output_0.append(predict_with_network(row, weights_0))
    
    # Append prediction to model_output_1
    model_output_1.append(predict_with_network(row, weights_1))

# Calculate the mean squared error for model_output_0: mse_0
mse_0 = mean_squared_error(target_actuals, model_output_0)

# Calculate the mean squared error for model_output_1: mse_1
mse_1 = mean_squared_error(target_actuals, model_output_1)

# Print mse_0 and mse_1
print("Mean squared error with weights_0: %f" %mse_0)
print("Mean squared error with weights_1: %f" %mse_1)

# =============================================================================
# Gradient descent
# =============================================================================

# Given function: get_slope(input_data, target, weights), get_mse(input_data, target, weights)

n_updates = 20
mse_hist = []   # mse history

# Iterate over the number of updates
for i in range(n_updates):
    # Calculate the slope: slope
    slope = get_slope(input_data, target, weights)
    
    # Update the weights: weights
    weights = weights - 0.01 * slope
    
    # Calculate mse with new weights: mse
    mse = get_mse(input_data, target, weights)
    
    # Append the mse to mse_hist
    mse_hist.append(mse)

# Plot the mse history
plt.plot(mse_hist)
plt.xlabel('Iterations')
plt.ylabel('Mean Squared Error')
plt.show()

# =============================================================================
# Backpropagation
# =============================================================================

# 沒有程式碼 XD

Python 3 Dictionary Keys Method

#!/usr/bin/python3

dict = {'Name': 'Zara', 'Age': 7}
print ("Value : %s" %  dict.keys())

3214

# Gyakorlatok 1.

print("\n indexszam: ")
sztring = "banan"
indexszamok = list(enumerate(sztring))
print(indexszamok)	    # [(0, 'b'), (1, 'a'), (2, 'n'), (3, 'a'), (4, 'n')]

print("\n darabszam: ")
sztring = "banan"
darabszamok = len(sztring)
print(darabszamok)      # 5

print("\n A lista egy elemenek a kiirasa: ")
primek = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
melyik_szam = primek[4]
print(melyik_szam)      # 11

print()
sztring = "banan"
melyik_betu = sztring[1]
print(melyik_betu)		# a

print()
baratok = ["Misi", "Petra", "Botond", "Jani", "Csilla", "Peti", "Norbi"]
melyik_barat = baratok[3]
print(melyik_barat)     # Jani

print("\n Megint indexszam: ")
primek = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]       # lista
index = list(enumerate(primek))
print(index)            # Na mi lesz?

print("\n Megint darabszam: ")
primek = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]       # lista
darab = len(primek)
print(darab)            # 11

print("\n Megint egy elem:")
primek = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]       # lista
egy_elem = primek[0]
print(egy_elem)         # ????

print("\n Lista index: list(enumerate()")
baratok = ["Misi", "Petra", "Botond", "Jani", "Csilla", "Peti", "Norbi"]
mi_az_indexuk = list(enumerate(baratok))
print(mi_az_indexuk)    # ????

print("\n Lista darab: len() ")
baratok = ["Misi", "Petra", "Botond", "Jani", "Csilla", "Peti", "Norbi"]
hany_barat = len(baratok)
print(hany_barat)       # 7

print("\n Lista elem: baratok[1]")
baratok = ["Misi", "Petra", "Botond", "Jani", "Csilla", "Peti", "Norbi"]
kicsoda = baratok[1]
print(kicsoda)      # Petra


print("\n Csoportositas n-es -el: ")

primek = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)

baratok = ("Misi", "Petra", "Botond", "Jani", "Csilla", "Peti", "Norbi")

szinesz = ("Julia", "Roberts", 1967, "Kettos jatek", 2009, "szineszno", "Atlanta, Georgia")

hallgatok = [
   ("Jani", ["Informatika", "Fizika"]),
   ("Kata", ["Matematika", "Informatika", "Statisztika"]),
   ("Peti", ["Informatika", "Konyveles", "Kozgazdasagtan", "Menedzsment"]),
   ("Andi", ["Informacios rendszerek", "Konyveles", "Kozgazdasagtan", "Vallalkozasi jog"]),
   ("Linda", ["Szociologia", "Kozgazdasagtan", "Jogi ismeretek", "Statisztika", "Zene"])]

julia_more_info = (("Julia", "Roberts"), (1967, "oktober", 8),
                   "szineszno", ("Atlanta", "Georgia"),
                   [("Sztarom a parom", 1999),
                    ("Micsoda no", 1990),
                    ("Izek, imak, szerelmek", 2010),
                    ("Erin Brockovich", 2000),
                    ("Alljon meg a naszmenet", 1997),
                    ("Egy veszedelmes elme vallomasai", 2002),
                    ("Oceans Twelve", 2004)])

print("\n Egy n-s elem: ")
elem1 = julia_more_info[2]
print(elem1)            # Kitalalod?

print("\n n-s darabszam: ")
darab_hany = len(julia_more_info)
print(darab_hany)       # ????????

print("\n n-s index -ek")
index_ek = list(enumerate(julia_more_info))
print(index_ek)         # 0 - meddig?


print("\n Hazi feladat: ")
szamok = ("123", "456", "789")
# Ez milyen csoport?
# Hany darab?
# Milyen elemekbol all?
# Mi van a 2 indexen?

Deep Learning in Python-Chapter 1

# =============================================================================
# Introduction to deep learning
# =============================================================================
'''
input_data: array([3, 5])
weights: {'node_0': array([2, 4]), 'node_1': array([ 4, -5]), 'output': array([2, 7])}
'''

# Calculate node 0 value: node_0_value
node_0_value = (input_data * weights['node_0']).sum()

# Calculate node 1 value: node_1_value
node_1_value = (input_data * weights['node_1']).sum()

# Put node values into array: hidden_layer_outputs
hidden_layer_outputs = np.array([node_0_value, node_1_value])

# Calculate output: output
output = (hidden_layer_outputs * weights['output']).sum()

# Print output
print(output)

''' The Rectified Linear Activation Function '''

def relu(input):
    '''Define your relu activation function here'''
    # Calculate the value for the output of the relu function: output
    output = max(input, 0)
    
    # Return the value just calculated
    return(output)

''' Applying the network to many observations/rows of data '''

# Define predict_with_network()
def predict_with_network(input_data_row, weights):

    # Calculate node 0 value
    node_0_input = (input_data_row * weights['node_0']).sum()
    node_0_output = relu(node_0_input)

    # Calculate node 1 value
    node_1_input = (input_data_row * weights['node_1']).sum()
    node_1_output = relu(node_1_input)

    # Put node values into array: hidden_layer_outputs
    hidden_layer_outputs = np.array([node_0_output, node_1_output])
    
    # Calculate model output
    input_to_final_layer = (hidden_layer_outputs * weights['output']).sum()
    model_output = relu(input_to_final_layer)
    
    # Return model output
    return(model_output)

# Create empty list to store prediction results
results = []
for input_data_row in input_data:
    # Append prediction to results
    results.append(predict_with_network(input_data_row, weights))

# Print results
print(results)  # [52, 63, 0, 148]
        
''' Multi-layer neural networks '''

# 在上述的 def 中,使用 "node_0_0" 標記多層節點

sachi_linkedlist

class Node:
    def __init__(self,data=None,next=None):
        self.data=data
        self.next=next
    def __repr__(self):
        return repr(self.data)
class Linkedlist:
    def __init__(self):
        self.head=None
    def __repr__(self):
        li=[]
        curr=self.head
        while(curr):
            li.append(repr(curr))
            curr=curr.next
        return "["+','.join(li)+"]"
    def prepend(self,data):
        self.head=Node(data,self.head)
    def append(self,data):
        curr=self.head
        if not curr:
            self.head=Node(data)
            return
        while(curr):
            if(curr.next==None):
                curr.next=Node(data)
            else:
                curr=curr.next
lst=Linkedlist
lst.prepend(1)
lst.append(2)
lst.append(3)
print(lst)
        
        
            
            

Find Hexadecimal Character

# Hello World program in Python
    
print(chr(int('0xFFFF',16)))

Execute Python-3 Online

liste=[["q1.gif","Informatique et Source du Numérique","Informatique et Sciences du Numérique","Information sur les Sciences Numériques","Information et Sciences du Numérique",2]
["q2.gif","L'anatomie d'une souris","La paresse","Les composants d'un ordinateur","Faire partie de l'élite de la nation",3]
["q3.gif","Une seule","Une infinité","Seulement deux","Une dixaine",3]
["q4.gif","0 et 1","1 et 2","921 et 156","Ce language n'existe pas",1]
["q5.gif","1000 octets","Un gros octet","1000000 d'octets","100 octets",3]
["q6.gif","numérique","numérico-analogique","analogique","aucune de ces proposition",1]
["q7.gif","a créer sa propre application","a créer son propre language","poser une question à l'ordinateur","constituer une suite d'ordre à un ordinateur",4]
["q8.gif","Une valeur qui n’a jamais une certaine valeurs","une valeur qui est susceptible de se modifier, de changer souvent","Une information temporaire","Une information durable et constante",2]
["q9.gif","<p/>","<add>","</strong>","<gras>",3]
["q10.gif","Entrer le corps d’un fichier html","De décrire le corps humaine","ecrire le titre de notre fichier","Cette balise n’existe pas",1]]

Prime Numbers

# Hello World program in Python

n=152
a=1
p=[]
while (a<n):
    a+=1
    if a==2 or a==3:
        p.append(a)
    for x in range(a):
        if x<2:
            x+=2
        if (a%x==0):
            flag=False
            print (a,x,'frueas')
            break
        else:
            flag=True
            print (a,x,'talse')
            
    if flag==True:
        p.append(a)
        print(a)
print (p)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.