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
    Shravya S
    Oct 30, 2021

    10/26 - Class 7 HW + Resources

    in Introduction to Python

    RESOURCES:

    Class slides: https://docs.google.com/presentation/d/1OzGQZc_DA0LFSBX92oApZWvSX5bW_tTdOiP6mNV2FvM/edit?usp=sharing

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


    HOMEWORK:

    Write a program that repeatedly takes in input as a number until "STOP" is inputted. Find the average of the numbers.

    Hint: Have an input inside of the while loop! (Look at the example code for how to do this.)


    Write your answer as a comment, and we’ll post the solution by next class. See you then!

    Note: VIP students, please contact us (Eric and me) about office hours. And of course, feel free to ask for help!

    3 comments
    0
    Eric Wu
    Nov 01, 2021  ·  Edited: Nov 02, 2021

    Solution:

    num=0

    len=0

    while x!="STOP":

    x=int(input())

    if x != "STOP":

    num = num+x

    len+=1


    print(sum/len)

    0
    jliu.mky
    Nov 02, 2021

    print('Please input your numbers and then type STOP when you are done'); num_sum = 0; user_input = input(); num_input = 0; num_average = 0; while (user_input != "STOP"): num_sum = num_sum + float(user_input); user_input = input(); num_input = num_input + 1; num_average = num_sum / num_input; print("User input is done"); print(f"Total number of inputs is {num_input}"); print(f"The sum of all the inputs is {num_sum}"); print(f"The average of the inputs is {num_average}");

    0
    jliu.mky
    Nov 02, 2021

    print('Please input your numbers and then type STOP when you are done'); user_input = input(); num_input =[]; num_average = 0; while (user_input != "STOP"): num_input.append(float(user_input)); user_input = input(); num_average = sum(num_input) / len(num_input); print("User input is done"); print(f"Total number of inputs is {len(num_input)}"); print(f"The sum of all the inputs is {sum(num_input)}"); print(f"The average of the inputs is {num_average}");

    0
    3 comments

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

    • lol-101dotcom

    ©2020 Legion of Learners