Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ex: python

def insertion_sort(data):
    for i in range(0, len(data)):
        insert_val = data[i]
        hole_pos = i

        while hole_pos > 0 and insert_val < data[hole_pos - 1]:
            data[hole_pos] = data[hole_pos - 1]
            hole_pos = hole_pos - 1

        data[hole_pos] = insert_val
Comment

ex:python

from sang import Sang
from spilleliste import Spilleliste

def hovedprogram():

    all_musikk = Spilleliste('Hele musikkbiblioteket')
    all_musikk.les_fil('musikk.txt')
    
    print("Tester spillAlle: Spiller alle sanger i listen:")
    all_musikk.spill_alle()
    print()
    
    ny_sang = Sang("Jahn Teigen", "Mil etter mil")
    print("Spiller ny sang:")
    all_musikk.spill_sang(ny_sang)
    print()   
	 
    all_musikk.legg_til_sang(ny_sang)
    print("Spiller alle sanger i listen inkl ny sang:")
    all_musikk.spill_alle() # pass på at rekkefølgen mellom Tittel
    print()
    
    funnet_sang = all_musikk.finn_sang("Mil etter mil")
    if funnet_sang is not None:
        print("Fant sangen:")
        all_musikk.spill_sang(funnet_sang)
    else:
        print("Fant ikke sangen
")
    assert(funnet_sang in all_musikk.hent_artist_utvalg("Jahn"))
    print()
    
    # Tester om flere sanger returneres for samme artist
    queen_liste = all_musikk.hent_artist_utvalg("Queen")
    print("Spiller sanger med Queen hentet fra listen: ")
    for queen_sang in queen_liste:
        queen_sang.spill()
    
    all_musikk.fjern_sang(funnet_sang)
    assert(not (funnet_sang in all_musikk.hent_artist_utvalg("Jahn")))
    
hovedprogram()
Comment

PREVIOUS NEXT
Code Example
Python :: how to change a particular text inside a list of dictionary 
Python :: pandas apply return dataframe 
Python :: a = np.array([0, 0, 0]) and a = np.array([[0, 0, 0]]) 
Python :: python check column conditions 
Python :: django auto complete light styling 
Python :: Issue TypeError: ‘numpy.float64’ object cannot be interpreted as an integer 
Python :: drop values in column with single frequency 
Python :: python to open .seg file 
Python :: python how to acquire the html code for a website 
Python :: email slicer in python code user input 
Python :: check if cuda is present in torch 
Python :: grading system in python with nested if 
Python :: the command 
Python :: create image tkinter set active background 
Python :: predict probabilities with xg boost 
Python :: how to remove na values in r data frame 
Python :: python import file from same directory 
Python :: colorama input python 
Python :: python hasattr function 
Python :: ipython list command history 
Python :: django form is onvalid 
Python :: Ranking in Pyspark 
Python :: Slice Age in Python 
Python :: ternary operator using dictionary in Python 
Python :: python assertRaises with class property 
Python :: gpg --verify Python-3.6.2.tgz.asc 
Python :: wexpect in python 
Python :: python unsigned to signed integer 
Python :: python object has no attribute 
Python :: abstract classes in python 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =