Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The highlighted part is the question... The code i have below is incorrect... wo variables, x and y, supposedly hold strings of digits. Write code
The highlighted part is the question... The code i have below is incorrect...
wo variables, x and y, supposedly hold strings of digits. Write code that converts these to integers and assigns a ariable z the sum of these two integers. Make sure that if either x and y has bad data (that is, not a string of digits), z will be assigned the value of -1 X 6 of 6: 2018-11-06 01:29:57- W SUBMIT 1 # string of digits 2 x = '456' 4 # string of digits 5 y 789 6 7 # check whether the variable x and y contains integer values or not 8 if (str.isdigit(x) and str.isdigit(y)): 9 10 11 mpx-int(x) 12 13 14 tmpY = int (y) 15 16 17 18 19 # If x and y contains bad data 20 else: 21 # Convert the x value into integer # Convert the y value into integer # sum of x and y # assign value of z as "-1" 23 24 25 print('Not a string of digits') 26 27 #Display the result on the screen 28 print( 'Sum is ',z)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started