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
    Jun 20

    6/19 - Homework Week 2 Day 2

    in Introduction to Python

    HOMEWORK:

    1. Take user input for a number and find its factorial (ex: 5! = 5 * 4 * 3 * 2 * 1 = 120) using a for loop.

    2. Take user input for someone’s full name. Then create a separate variable for only their first name, and greet them in the format “Have a great day, {firstName}!”

    3. One approach: For loop to locate space. First name = before space.

    4. Use nested loops to print 3 rows: the first with all numbers from 1 to 10, the second with all their squares, and the third with all their cubes.

    5. Use end=' ' parameter in inner loop and print(‘\n’) in your outer loop (under the inner loop) for correct spacing.

    RESOURCES:

    Class slides:

    https://docs.google.com/presentation/d/1DpbCZWxsHFFkeYu6DJOHEDSKzi0I0DudeHR8OiBTSK0/edit?usp=sharing

    Example code: https://replit.com/@ShravyaS/IntroToPython-Wk2Day2

    Coding platform: replit.com

    Post your answers as a comment! I will post the solution before next class.

    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.

    4 comments
    0
    echeung0808
    6일 전

    Problem 1:

    numStr = input("give me a number ")

    num = int(numStr)

    factorial = 1

    for i in range(1, num+1):

    factorial = factorial*i

    print(factorial)


    Problem 2:

    firstName = ""

    for i in input ("what is your full name? "):

    firstName = firstName + i

    if i == " ":

    print("Have a great day, "+firstName+"!")


    Problem 3:

    for i in range(1, 4):

    for j in range(1, 11):

    print(str(j**i) + " ", end = "")

    print('\n')


    0
    davidkouhouchin
    5일 전

    numStr = input("number")

    num = int(numStr)

    factorial = 1

    for i in range(1, num+1):


    factorial = factorial*i

    print(factorial)


    name1 = ""


    for i in input ("what is your full name? "):


    name1 = name1 + i


    if i == " ":


    print("Have a great day, "+name1+"!")

    0
    chiao_chuanhung
    4일 전  ·  Edited: 4일 전

    num = int(input("Enter a number: "))

    ans=1

    for i in range(1,num+1,1):

    ans*=i


    print("factorial "+str(num)+"!="+str(ans))

    -----------------

    fullname = input("Enter your full name:")

    firstname =""

    for c in fullname:

    if c!=" " :

    firstname+=c

    else:

    break

    print("Have a great day, "+firstname+"!")

    -----------------

    for j in range (1,4):

    for i in range(1,11):

    print(i**j , end=' ')

    print("\n")

    ----------------------

    0
    Eric Wu
    4일 전  ·  Edited: 4일 전

    Solution:

    Part 1:

    x=int(input())

    num=1

    while x >0:

    num=num*x

    x=x-1

    print(num)


    Part 2:

    name=input()

    firstname=""

    for char in name:

    if char == " ":

    break

    firstname+=char

    print(f'Have a great day, {firstname}!')


    Part 3:

    for i in range(1,11):

    print(i, end=' ')

    print()

    for i in range(1,11):

    print(i*i, end =' ')

    print()

    for i in range(1,11):

    print(i*i*i, end =' ')

    0
    4 comments

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

    • lol-101dotcom

    ©2020 Legion of Learners