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
sladkih [1.3K]
3 years ago
7

Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th

ese to integers and print the sum of these three integers. However, if any variable has a value that cannot be converted to an integer, print out, the string "bad value(s) in: " followed by the names of the variables that have bad values (separated by spaces, in alphabetically ascending order). For example, if the values of x, y and z were respectively "3", "9", "2" then the number 14 would be printed; but if the values were "abc", "15", "boo" then the output would be: bad value(s) in: x z
Computers and Technology
1 answer:
sineoko [7]3 years ago
5 0

Answer:

Required code is given below:

Explanation:

x, y, z = "abc", "15", "boo"

errors = []

try:

   x = int(x)

except ValueError:

   errors.append('x')

try:

   y = int(y)

except ValueError:

   errors.append('y')

try:

   z = int(z)

except ValueError:

   errors.append('z')

if len(errors) == 0:

   print(x+y+z)

else:

   print('bad value(s) in: ' + ' '.join(errors))

You might be interested in
A positive return on investment for higher education.
lesya692 [45]

Answer: is when your earnings potential is higher than the cost of your education

Explanation:

A positive return on investment on a particular thing occurs when the benefit derived is more than the cost that was incurred while in a scenario whereby the cost is more than the benefit, a negative return on investment took place.

In this case, a positive return on investment for higher education occurs when your earnings potential is higher than the cost of your education.

5 0
2 years ago
Write a program that creates a linked list object of 10 characters and creates a second list object containing a copy of the fir
slamgirl [31]

Answer:

Below code is in c++ with explanation.

Explanation:

Explanation is in comment format, any line starting with //.

#include <iostream>

#include <cstdlib>

using namespace std;

//creating a Node struct which holds node data

struct Node {  

  char data;  

  struct Node *next;  

};  

//creating variable of Node as head

// this head is the start point of ordered Linked list

struct Node* head = NULL;    

// This method is used to insert new value in node

void insert(char new_data) {  

// allocating the memory for new node

  struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));  

// assigning the data to new node

  new_node->data = new_data;  

// If head == null then it means we are inserting first value

// it will return after creating first node and assign it to

// head as head is the entry point

  if(head == NULL){

    new_node->next=NULL;

   head=new_node;

    return;

  }

// Now we need to treverse to end of linked list

// that's why creating a lastNode variable  

// As we don't want our head to point any other node

// except first node

  Node* lastNode = head;

  while(lastNode->next != NULL){

   lastNode=lastNode->next;

  }

// as last node next will be null to end the traversing  

// on linked list

  new_node->next= NULL;

// assigning last node to its previous node  

  lastNode->next = new_node;  

   

}  

// This variable will hold the first node for reverse linklist

struct Node* reverseHead = NULL;    

// This method will reverse the ordered linklist

void reversLinkList(){

  Node* lastNode = head;

// traversing the ordered linklist

  while(lastNode!= NULL){

// creating new linked list

   struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));  

   new_node->data = lastNode->data;  

   new_node->next = reverseHead;  

   reverseHead = new_node;  

   lastNode = lastNode->next;

  }

   

}

// display method will travers the linklist that

// was passed throw paramter

void display(Node* node) {  

  struct Node* ptr;

  ptr = node;

  while (ptr != NULL) {  

     cout<< ptr->data <<" ";  

     ptr = ptr->next;  

  }  

}  

// main method is the entry point of this program

int main() {  

// adding 10 nodes by calling insert method

  insert('a');

  insert('b');

  insert('c');

  insert('d');

  insert('e');

  insert('f');

  insert('g');

  insert('h');

  insert('i');

  insert('j');

  cout<<"The Ordered linked list is: ";

// calling display method with head to print ordered linklist

  display(head);  

  cout<<endl;

  cout<<"The Reversed linked list is: ";

// calling reversLinkList to reverse the ordered linklist

  reversLinkList();

// calling display method with reverseHead to display  

// reversed linklist

  display(reverseHead);

   

  return 0;  

}

4 0
3 years ago
A(n) _____ of an class is where the services or behaviors of the class is defined. (Points : 6) operation
k0ka [10]

Answer:

Operation the correct answer for the given question.

Explanation:

An operation is a template that is used as a template parameter .An operation defined the services and behaviors of the class .The operation is directly invoked on instance .

Attribute define the property of an entity it is not defined the services and behaviors of the class. so this option is incorrect.

Class is the class of variable of method it is not defined the services and behaviors of the class  so this option is incorrect.

Object are the rub time entity .object are used access the property of a class it is not defined the services and behaviors of the class  so this option is incorrect.

Abstract class is the class which have not full implementation of all the method .it is not defined the services and behaviors of the class  so this option is incorrect.

So the correct answer is operation.

6 0
3 years ago
Misty is creating a professional development plan to advance in her current career. She has identified what job she wants, what
Leona [35]
I think the answer is C. It makes the most sense.
6 0
3 years ago
Read 2 more answers
The _________keys include the home, end, and arrow keys.
katovenus [111]
The answer would be Functional Keys.
8 0
2 years ago
Other questions:
  • Which data type uses more memory an integer or an unsigned integer?
    6·1 answer
  • how much should an organization consider moving into the cloud before full outsourcing starts making more business sense
    14·2 answers
  • Professionalism is defined as what?<br> ASAP PLEASE!
    11·1 answer
  • opearating system protection refers to a mechanism for controling access by programs, processes, or users to both system and use
    7·1 answer
  • What is the keyboard shortcut used to paste previously copied text?
    15·2 answers
  • _____________ describes the abstraction of web-based computers, resources, and services that system developers can utilize to im
    9·1 answer
  • Since the rules cannot address all circumstances, the Code includes a conceptual framework approach for members to use to evalua
    8·1 answer
  • What makes a source credible?
    9·2 answers
  • Which of the following statements is correct? User data cannot be combined and shared among authorized users. In a nondatabase,
    6·1 answer
  • Instructions
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!