Sum of odd numbers using while loop in python

0 votes

I'm new to programming, I was asked to use a while loop to add all odd numbers between 1 and (2*n)-1.

def sum_odd_n(n):
    while n<2*n:
        sum = 0
        if n%2==1:
            sum = sum+n
    return (sum)

I cannot find my mistake. Please help

Feb 16, 2023 in Python by Arya
• 990 points

edited 5 days ago 11 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP