1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Zigmanuir [339]
2 years ago
9

Use list indexing to print the last element of the list literal value.

Computers and Technology
1 answer:
AnnZ [28]2 years ago
4 0

Answer:

print(["Not me", "Nor me", "Print me!"][2])

Explanation:

Given

print(["Not me", "Nor me", "Print me!"])

Required

Print last element of the list literal value

The implication of this question is to print "Print me!"

We start by analysing the given list.

The given list has 3 elements

But because indexing of a list starts from 0, the index of the last element will be 3 - 1 = 2

So, to print the last element, we simply direct the print statement to the last index.

This is done as follows

print(["Not me", "Nor me", "Print me!"][2])

The [2] shows that only the literal at the last index will be printed.

This means that the string "Print me!" will be printed.

The code can also be rewritten as follows

mylist = ["Not me", "Nor me", "Print me!"]

print(mylist[2])

Here, the first line stores the list in a variable.

The second line prints the last element of the list literal value which is "Print me!"

You might be interested in
A four-year old laptop will not boot and presents error messages on screen. you have verified with the laptop technical support
vodka [1.7K]
Could I buy A WAY better one this one for a lower price
6 0
3 years ago
The Syntax NPV formula includes the Rate, The Cash Flows, the number of payments, and the Future
Tems11 [23]

Answer:

False

Explanation:

NPV stands for Net Present Value, it is an important term in finance as it used to determine the value of money or investment based on a series of cashflows and specified discount rate. Excel provides a functions which aids easy calculation of the Net Present value of money or investment using the NPV formula. The syntax forbthe NPV formula is :

=NPV(rate,value 1, [value 2],...)

This formular requires only tow key parameters ; the discount rate, which comes first and the cashflows, which is designated in the syntax as values ; the cashflows is usually placed in a range of cells in excel and the cell range is inputed in the formular. Hence, the number of payments and future value aren't part of the NPV syntax.

5 0
2 years ago
Write a C function that takes an STL vector of int values and determines if all the numbers are different from each other (that
eduard

Answer:

Here is the function:

#include <iostream>  //to use input output functions

#include <vector>  // to use vector (sequence containers)

#include <algorithm>   //use for sequence operations

#include<iterator>  //to move through the elements of sequence or vector

using namespace std;  //to identify objects cin cout

 void DistinctNumbers(std::vector<int> values) { /*function that takes  an STL vector of int values and determines if all the numbers are different from each other */

     sort(values.begin(), values.end());  //sorts the vector elements from start to end

     bool isDistinct = std::adjacent_find(values.begin(), values.end()) == values.end();  //checks for occurrence of two consecutive elements in vector

if(isDistinct==true)  // if all numbers are different from each other

{cout<<"Numbers are distinct";}

else  //if numbers are duplicate or same

{cout<<"Numbers are not distinct";}   }  

int main(){      //start of main function

std::vector<int> v = {1,2,3,4,5};  // vector of int values

DistinctNumbers(v); }  //function call to passing the vector v to check if its elements are distinct

Explanation:

The program that takes an STL vector of int values and the function DistinctNumbers determines if all the numbers are different from each other. It first sorts the contents of the vector in ascending order using sort() method. Then it used the method adjacent_find() to searches the range means from the start to the end of the vector elements, for first occurrence of two consecutive elements that match, and returns an iterator to the first of these two elements, or last if no such pair is found. The result is assigned to a bool type variable isDistinct. It then checks if all the numbers are different and no two adjacent numbers are same. If all the numbers are distinct then this bool variable evaluates to true otherwise false. If the value of isDistinct is true then the message :Numbers are distinct is displayed on screen otherwise message: Numbers are not distinct is displayed in output screen.

7 0
3 years ago
Create a program that displays a menu to select addition, subtraction, or multiplication. Using random numbers between 0 and 12
Lemur [1.5K]

Answer:

This question is answered using C++

#include<iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main(){

   int ope, yourresult;

   cout<<"Select Operator: \n"<<"1 for addition\n"<<"2 for subtraction\n"<<"3 for multiplication\n";

   cout<<"Operator: ";

   cin>>ope;

   srand((unsigned) time(0));

   int num1 = rand() % 12;

   int num2 = rand() % 12;

   int result = 1;

   if(ope == 1){

       cout<<num1<<" + "<<num2<<" = ";

       result = num1 + num2;

   }

   else if(ope == 2){

       cout<<num1<<" - "<<num2<<" = ";

       result = num1 - num2;

   }

   else if(ope == 3){

       cout<<num1<<" * "<<num2<<" = ";

       result = num1 * num2;

   }

   else{

       cout<<"Invalid Operator";

   }

   cin>>yourresult;

   if(yourresult == result){

       cout<<"Correct!";

   }

   else{

       cout<<"Incorrect!";

   }

   return 0;

}

Explanation:

This line declares operator (ope) and user result (yourresult) as integer

   int ope, yourresult;

This prints the menu

   cout<<"Select Operator: \n"<<"1 for addition\n"<<"2 for subtraction\n"<<"3 for multiplication\n";

This prompts the user for operator

   cout<<"Operator: ";

This gets user input for operator

   cin>>ope;

This lets the program generates different random numbers

   srand((unsigned) time(0));

This generates the first random number

   int num1 = rand() % 12;

This generates the second random number

   int num2 = rand() % 12;

This initializes result to 1

   int result = 1;

If the operator selected is 1 (i.e. addition), this prints an addition operation and calculates the actual result

<em>    if(ope == 1){</em>

<em>        cout<<num1<<" + "<<num2<<" = ";</em>

<em>        result = num1 + num2;</em>

<em>    }</em>

If the operator selected is 2 (i.e. subtraction), this prints an subtracttion operation and calculates the actual result

<em>    else if(ope == 2){</em>

<em>        cout<<num1<<" - "<<num2<<" = ";</em>

<em>        result = num1 - num2;</em>

<em>    }</em>

If the operator selected is 3 (i.e. multiplication), this prints an multiplication operation and calculates the actual result

<em>    else if(ope == 3){</em>

<em>        cout<<num1<<" * "<<num2<<" = ";</em>

<em>        result = num1 * num2;</em>

<em>    }</em>

If selected operator is not 1, 2 or 3, the program prints an invalid operator selector

<em>    else{</em>

<em>        cout<<"Invalid Operator";</em>

<em>    }</em>

This gets user input

   cin>>yourresult;

This checks if user result is correct and prints "Correct!"

   if(yourresult == result){

       cout<<"Correct!";

   }

If otherwise, the program prints "Incorrect!"

<em>    else{</em>

<em>        cout<<"Incorrect!";</em>

<em>    }</em>

   return 0;

6 0
3 years ago
Why is a niche important in video production
abruzzese [7]

Answers

You need a niche to start your recording for let's say commentary you'll need that for your commentary.

7 0
2 years ago
Read 2 more answers
Other questions:
  • These are questions from my Computer/Customer Support Class
    6·1 answer
  • Comet Computer Company will make a splash with psychedelic laptop cover designs scheduled for release next year. The computers d
    11·1 answer
  • Question 16 of 20
    12·2 answers
  • Which term refers to the blank areas surrounding a document page? *
    15·1 answer
  • To accomplish a certain task when you would rsther be doing something else is an example of
    9·1 answer
  • 22
    15·1 answer
  • In this lab, you use the flowchart and pseudocode found in the figures below to add code to a partially created C++ program. Whe
    9·1 answer
  • 1.Which one of the following buttons returns a window to its original size?
    11·1 answer
  • All of the following are true about data science and big data except: a.Digital data is growing at the rate of 2.5 quintillion b
    15·1 answer
  • Java what are synchronized functions.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!