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.
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()
1 Show the output from the following Python code fragment: for i in [ 12, 4,...
I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code...
(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 = 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 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. 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:
#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 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...
In Python: What is the output of the following code? for i in range(5): if i == 2: continue print(i) Question 22 options: 0 1 2 4 0 1 3 4 0 1 3 0 1 4
1. What would be the output of the following lines of code: int num = 2; switch(num){ case 1: cout << "1"; case 2: cout << "2"; case 3: cout << "3"; case 4: cout << "4"; } 2. What would be the output of the following code: char op = '*'; switch(op){ case '+': cout << "Addition"; break; case '-': cout << "Subtraction"; break; case '/': cout << "Division"; break; default: cout << "Invalid"; } 3. What would be...
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...