Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 2 - Elementary Programming - Section 2.11 - Type Conversions and Rounding - Check Point - MyProgrammingLab - Page 46: 2.18

Answer

4 5 22 4 4 Error due to leading zeros in eval statement

Work Step by Step

int(value): it's a type conversion to int and because the value is a float, it can be changed to an int by truncating the float, hence it becomes 4 round(value): it's a float and can be rounded up making the answer 5 eval("4 * 5 + 2"): the statement is syntactically correct because it has a mathematical expression. it's evaluated as (4*5) which is 20 + 2 = 22 int("04"): because the string is a number, type conversion is valid int("4.5"): because the string is a number, type conversion is valid and the float is truncated, making the answer 4 eval("04")": this is not a mathematical expression and because there are leading zeros, it is syntactically incorrect
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.