• 2-Laboratoriya
  • Dasturga Muqaddima 1-bosqich




    Download 5.67 Mb.
    bet31/31
    Sana22.10.2022
    Hajmi5.67 Mb.
    #27828
    1   ...   23   24   25   26   27   28   29   30   31
    Bog'liq
    Uzb coders qollanma
    TITUL 2 (3), PM 5-2-Ma\'ruza (2), Qurilish mashinalarini bir ish joyidan boshqa ish joyiga uni qo, 1-маъруза, 2-amaliy ishga Javoblar, 2-amaliy ish, 1-2-mustaqil ish mavzulari (1), Birgalikda Korrupsiyani To\'xtatamiz

    23-qism


    Topshiriq



    Kodi:
    import random
    import words


    def silly_string(nouns, verbs, templates):
    # Choose a random template.
    template = random.choice(templates)


    # We'll append strings into this list for output.
    output = []


    # Keep track of where in the template string we are.
    index = 0


    while index < len(template):
    if template[index:index+8] == '{{noun}}':
    # Add a random noun to the output.
    output.append(random.choice(nouns))
    index += 8
    elif template[index:index+8] == '{{verb}}':
    # Add a random verb to the output.
    output.append(random.choice(verbs))
    index += 8
    else:
    # Copy a character to the output.
    output.append(template[index])
    index += 1


    # Join the output into a single string.
    output = ''.join(output)


    return output


    if __name__ == '__main__':
    print(silly_string(words.nouns, words.verbs,
    words.templates))


    2-Laboratoriya



    Kod:
    text = "this is not a reversed text"


    def reverse(x):
    temp=''
    l=len(x)
    for i in range(l):
    temp+=x[l-i-1]
    return temp


    print("the reversed text is: "+reverse(text))

    Kod:
    no_list = [22,68,90,78,90,88]


    def average(x):
    av=0
    for a in x:
    av+=a
    av=av/len(x)
    return av



    print(average(no_list))


    Kod:
    no_list = [1,2,3,4]


    def maximum(x):
    mx=0
    for a in x:
    if mx
    mx=a
    return a


    print(maximum(no_list))


    Kod:
    no_list = [22,22,2,1,11,11,2,2,3,3,3,4,5,5,5,55,55,66]


    def unique_list(l):
    unil=[]
    for a in no_list:
    if a not in unil:
    unil.append(a)
    return unil


    print(unique_list(no_list))
    Download 5.67 Mb.
    1   ...   23   24   25   26   27   28   29   30   31




    Download 5.67 Mb.