Question

1 Show the output from the following Python code fragment: for i in [ 12, 4,...

1 Show the output from the following Python code fragment:

for i in [ 12, 4, -2]:

     print (2 * i)

2 Write a Python program findAverage to find the average of the numbers in a range defined by two inputs num1 and num2, where the values of num1 and num2 are entered by the user. For example, a call to findAverage(2,10) would find the average of the numbers 2,3,4,5,6,7,8,9 (note the final "10" is NOT included!). The output of this particular call would be 5.5.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Question 1:
Output is
24
8
-4

===================================
Question 2:
def findAverage(num1, num2):
    s = 0
    for i in range(num1, num2):
        s += i
    return s/(num2-num1)

def main():
    num1 = int(input("Enter value for num1: "))
    num2 = int(input("Enter value for num2: "))
    avg = findAverage(num1,num2)
    print(avg)

main()
Add a comment
Know the answer?
Add Answer to:
1 Show the output from the following Python code fragment: for i in [ 12, 4,...
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
  • (C++) What is the best way to validate for the two user inputs in the followig...

    (C++) What is the best way to validate for the two user inputs in the followig for loop? Would like it to say "That value is not allowed. Enter another value." , if 1 ) numbers are not within range 2) a blank is entered 3) other characters (that are not numbers) are entered and 4) numbers with decimals or negatives are entered. int num1; int num2; for(int i = 1; i <= 4; i++) { cout << "Enter number...

  • What is the output of the following Python code if the user enters 4? count =...

    What is the output of the following Python code if the user enters 4? count = int(input()) the_sum = 0 for i in range (1, count):     the_sum = the_sum + i print("Sum is", the_sum)

  • This is a fill in the code type: // FILL IN THE CODE - Write a...

    This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() {   int num1;       // holds 1st number   int num2;       // holds 2nd number   int result;       // holds result of multiplication   int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number   int *num2Ptr...

  • EX 1) Determine the outcome of the following code fragment without writing and running the program....

    EX 1) Determine the outcome of the following code fragment without writing and running the program. int num = 0, max = 20; while (num <= max) {     System.out.println(num);     num += 4; } EX 2) Write a code fragment that reads and prints integer values entered by user until a particular sentinel value (stored in constant SENTINEL) is entered. Do not print the sentinel value.                 Ex 3)  Write a method called averageLargestTwo  that accepts three int parameters  and returns the average...

  • May i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #...

    may i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #include<iostream> #include<string> #include<sstream> #include<stack> using namespace std; int main() { string inputStr; stack <int> numberStack; cout<<"Enter your expression::"; getline(cin,inputStr); int len=inputStr.length(); stringstream inputStream(inputStr); string word; int val,num1,num2; while (inputStream >> word) { //cout << word << endl; if(word[0] != '+'&& word[0] != '-' && word[0] != '*') { val=stoi(word); numberStack.push(val); // cout<<"Val:"<<val<<endl; } else if(word[0]=='+') { num1=numberStack.top(); numberStack.pop(); num2=numberStack.top(); numberStack.pop();...

  • Task 1: Calling a Function PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS Task...

    Task 1: Calling a Function PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS Task 1: Calling a Function Defining a function gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code. Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is an example to call the printme() function #!/usr/bin/python 3...

  • can anyone show me how this code would look in python, I'm studying python while taking...

    can anyone show me how this code would look in python, I'm studying python while taking some classes. I can't seem to understand what this is asking for. • Phase 1 Requirements Code submitted for Phase 1 will only have the following capability. Any additional coding will result in the loss of point. • code will have the main function, including looping until the user enters input of 12 • code will call the printMenu() function • The printMenu() function...

  • Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX =...

    Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX):     message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user     num = int(input(message))     while num < MINN or num > MAXX:         print("Invalid choice!")         num = int(input(message))     #return result     return num #counts dupes def twoInARow(numbers):     ans = "No duplicates next to each...

  • What is the output of the following code fragment? int i = 1; while( i <=...

    What is the output of the following code fragment? int i = 1; while( i <= 5 ) if(i == 2 || i == 4) System.out.println(i + ":" + " is an even index) System.out.println("i: " + i); i++;

  • Write the output from the following code fragment: for (int i = 1; I < 7;...

    Write the output from the following code fragment: for (int i = 1; I < 7; ++i) { switch (i) { case 1: printf ("\n%d Banana", i); case 2: printf ("\n%d Kumquat", i);

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