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
Problem: Write the Python code of a program called ComputeSquare that asks the user to enter the length of the side of the squar
Lera25 [3.4K]
<h2>Solution :</h2>

The given problem is solved in Python.

def ComputeSquare():

side = float(input('Enter the side of the square: '))

if side > 0:

perimeter = 4 * side

area = side * side

print('Perimeter of the square is:',

perimeter, 'unit.')

print('Area of the square is:', area, 'square unit.')

<h3> else:</h3>

print('Invalid input.')

ComputeSquare()

<h2>Explanation :-</h2>

  • In this program, we create a function ComputeSquare() to calculate the perimeter and area of a square.

  • The function asks the user to enter the side of the square. The side is then stored in a variable.

  • Now, we check whether the side is greater than 0 or not using if-else statement.

  • If the condition is true, the perimeter and area is calculated which is displayed using print() statement.

  • If the condition is false, the else blocks executes printing the error message.

<h3>Refer to the attachment for output.</h3>

6 0
2 years ago
Hi can someone please help me with this homework please?
notka56 [123]

Answer: How is someone suppose to help those aren't straight questions theres a whole other site you have to go to for that.

4 0
1 year ago
Consider an array of length n containing positive and negative integers in random order. Write C++ code that rearranges the inte
Vika [28.1K]
A=243484318731872913781675784
3 0
3 years ago
A program written in a(n) procedural language consists of sequences of statements that manipulate data items. __________________
Alenkasestr [34]

Answer:

true.

Explanation:

According to my research on information technology, I can say that based on the information provided within the question the statement is completely true. Procedural programming is a widely used paradigm that basically gives the program a set of routines or specifications, and the program mixes and matches them as they continuously repeat the process. It is used in many areas, including video game development.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

7 0
3 years ago
Your computer has two basic types of software: system software and ________ software.
Elan Coil [88]
Hi!

Our computers will have system software and application software. Application software would be something like a game or just any general purpose app you've downloaded.

Hopefully, this helps! =)
5 0
3 years ago
Other questions:
  • Internally, computers are constructed from circuitry that consists of small on/off switches. What is the most basic circuitry-le
    12·1 answer
  • Researching the history of computers is a good troubleshooting technique.<br> True or False?
    5·1 answer
  • What is a binary message
    12·2 answers
  • The flynn effect best illustrates that the process of intelligence testing requires up-to-date ________
    14·1 answer
  • Analyze the following code: class Test { public static void main(String[] args) { System.out.println(xMethod((double)5)); } publ
    7·1 answer
  • What is the purpose of the new window command
    6·1 answer
  • What are other ways you could use the shake or compass code blocks in physical computing projects?
    14·1 answer
  • If Anyone can help me out that'll be great
    11·1 answer
  • After creating a webpage with html code, what do you need to do so that others can access it on the internet?.
    11·1 answer
  • There are a wide variety of nonsampling errors that can occur during data collection including the first type, ________.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!