Question

Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...

Python Programming assignment :

Function of Q3:

def isPositive(n):

if(n>=0):

return True

else:

return False

Write a code for function main, that does the following:

-creates a variable and assigns it the value True.

- uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to a running sum. Otherwise, make the loop stop without using break.

- After the loop stops, print the running sum of all the values the user entered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def isPositive(n):
    if(n>=0):
        return True
    else:
        return False

def main():
    var = True
    total = 0
    while(var):
        n = int(input("Enter a number: "))
        var = isPositive(n)
        if(var):
            total += n
    print("Total =",total)


main()
        
Add a comment
Know the answer?
Add Answer to:
Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...

    Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...

  • Required functions def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard....

    Required functions def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard. The function will only return a value that is within the inclusive range of lowValue to highValue. If the entered value is not within the provided range, the function will ask again until the user has entered an acceptable value. The function will return the accepted value. def doContinue (prompt): This function will ask for a string using the prompt parameter. The function will...

  • def ged(m,n) : if m n == 0: return n else: return god (n, møn) Without...

    def ged(m,n) : if m n == 0: return n else: return god (n, møn) Without typing the code into Python, what are the values of the input arguments of the second recursive call if the function gcd is called from the main program as gcd(537,44)? (Hint: do not count the initial call to the function from the main program) Om = 44, n = 9 Om = 44, n = n = 537 Om = 9, n = 8...

  • Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...

    Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...

  • Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...

    Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is. Please remember the following two guidelines: unless the purpose of the function is to generate output DO NOT write to the screen within the function unless the purpose...

  • Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n):...

    Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n): 2 "*"Returns the nth Fibonacci number. " 3 if n < 3: lil 4 return 1 Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib You will need to create a dictionary to cache the sum of the fib function. The base case of...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • in python 3 1. A program contains the following function definition: def cube(num): return num *...

    in python 3 1. A program contains the following function definition: def cube(num): return num * num * num Write a statement that passes the value 4 to this function and assign its return value to the variable result. 2. Write a function named get_first_name that asks the user to enter his or her first name and returns it.

  • For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...

    For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT