Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 8 Optional User Input Python Version Issues #281

Open
resmins opened this issue Jul 30, 2022 · 0 comments
Open

Chapter 8 Optional User Input Python Version Issues #281

resmins opened this issue Jul 30, 2022 · 0 comments

Comments

@resmins
Copy link

resmins commented Jul 30, 2022

The problem below these words:

"A bug free program that behaves as intended looks like this:"

ERROR: The Ada solution has a typeError because the code does not compile in the Python 2.x used by Ada.

Which is still incorrect
Not typeError

INSTEAD

Syntax Error
WHY?
input() is used in Python 3.x
raw_input() is used in Python 2.x ***input was used instead of raw_input in the ADA problem

Additionally

print(f"That's a great age! I am {36 - age} years older than you")*** python 2.x Inaccurate
Why?
"f" for format is used in python 3.x not in python 2.x

ALSO
print(f"That's a great age! I am {36 - age} years older than you") ***python 3.x Accurate BUT inaccurate in python 2.x which ADA uses

Correct print in python 2.x:
print("That's a great age! I am " + str(36 - age) + " years older than you") ***python 3.x Accurate
WHY?
After converting age into an int from the input given by the user. You must convert the int (36 - age) into a string because you are adding "+" it to the string on the left side "Thats a great age! I am " and to the string on the right side " years older than you"

The updated code for Python 2x

**won't comply in the ADA code cell because we can't rewrite the code ourselves
** Does Comply in an online Python Complier

age = raw_input("How old are you? ")

age = int(age)

output the difference in your ages

print("That's a great age! I am " + str(36 - age) + " years older than you")

HOWEVER, the original code is accurate with Python 3.x ONLY **which ADA doesn't use

How old are you? 31
That's a great age! I am 5 years older than you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant