logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    Eric Wu
    Aug 01

    7/27 - Homework Week 7

    in Introduction to Python

    There was no class on Sunday last week so there is no recording for that day.


    Homework:

    1. Use recursion to determine the nth term of an arithmetic series. Parameters: starting term, common difference, n. The formula for the nth term is a_n=a_(n-1)+d.

    2. Write a lambda that checks if a tuple of integers is a square. Then apply map() and print out the list result. (Hint: one approach is to use math.sqrt()).


    Resources:

    Slides: https://docs.google.com/presentation/d/1geOoU09YAzWQuYqReMEQ-y8erSqyeew6ESyH28_RRD0/edit?usp=sharing

    Class code: https://replit.com/join/lqjxuqxbqy-shravyas


    You can always email us at shravyassathish@gmail.com (mentor) or kingericwu@gmail.com (TA) or message us on Discord if you have any questions about the homework or what we covered in class.

    3 comments
    0
    3 Comments
    Darrin Lin
    Aug 04

    # homework 1

    def arithmetic(start, d, n):

    if n==1:

    return start

    else:

    return arithmetic(start, d, n-1)+d


    print(arithmetic(1,3,3))


    # homework 2

    import math


    tuple1 =(1,2,4,5,9,100,24,49,50)


    l1 =list(map(lambda x: math.sqrt(x).is_integer(), tuple1))

    print(tuple1)

    print(l1)


    Like

    justannie2019
    Aug 03

    def recursionSequence(n, d):

    x = 0

    nthTerm = x + d

    for i in range(n):

    nthTerm += nthTerm

    nthTerm += d

    x += nthTerm

    return nthTerm


    tuple1 = (1, 2, 3, 4, 5)


    import math

    print(list(map(lambda x : math.sqrt(x) == int(math.sqrt(x)), tuple1)))

    Like

    melodychangchang
    Aug 03

    import math


    Part 1:

    def term(start, diff, nTerm, nTerm2):

    nTerm = start + diff*(nTerm-1)

    return f"Term #{nTerm2} of the arithmetic series with first term {start} and common difference {diff}: {nTerm}"


    print(term(1, 2, 3, 3))




    Part 2:

    tuple = (1, 9, 4, 16, 15, 13, 54, 16, 257, 322, 64, 987)


    print(list(map(lambda i : int(math.sqrt(i)) == math.sqrt(i), tuple)))

    Like
    3 comments
    Similar Posts
    • Intro to Java 6/27 Homework
    • 7/10 - Homework Week 5 Day 1
    • 7/13 - Homework Week 5 Day 2

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2022 Legion of Learners