Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The task for this was to Fix the errors and then run the program. Each time you fix an error, add a # comment in

The task for this was to
Fix the errors and then run the program.
Each time you fix an error, add a # comment in the line where you fixed it
and indicate which of the three types of errors it was with a brief
explanation of why that is
''' original block'''
# This example program is meant to demonstrate errors.
# There are some errors in this program. Run the program, look at the error messages, and find and fix the errors.
print "Welcome to the error program"
print "
"
# Variables declaring the user's age, casting the str to an int, and printing the result
age_Str =="24 years old"
age = int(age_Str)
print("I'm"+ age + "years old.")
# Variables declaring additional years and printing the total years of age
years_from_now ="3"
total_years = age + years_from_now
print "The total number of years:" + "answer_years"
# Variable to calculate the total amount of months from the total amount of years and printing the result
total_months = total *12
print "In 3 years and 6 months, I'll be "+ total_months +" months old"
#HINT, 330 months is the correct answer
'''print "Welcome to the error program" ''' # syntax error: needs parentheses in Python 3, so change it to
'''print "
"''' # syntax error, requires parentheses and also can be added onto end of string to indicate start of new line
print("Welcome to the error program
")
'''age_Str =="24 years old" ''' # should assign the string "24" to age_Str.
age_Str =("24")
'''print("I'm"+ age + "years old.")''' # Change age to a string to concatenate it
print(f"I'm {age_Str} years old.")
years_from_now ="3" # change to an integer, so
years_from_now =3
'''total_years = age + years_from_now''' # syntax error but also logical error possibly, needs sum function here
nums =[24,3]
total_years = sum(nums)
'''print "The total number of years:" + "answer_years" ''' # syntax error no parentheses, name error - answer_years not defined, perhaps should be 'total_years', also print statement could be clearer to user
print("The total number of years: ", total_years)
num2=6
'''total_months = total 12''' # parentheses missing and asterix missing for multiplication #syntax error, again maybe logical error again is inaccurate
total_months =(total_years*12)
'''print "In 3 years and 6 months, I'll be "+ total_months +" months old" '''
print(f"In 3 years and 6 months, I'll be {str(total_months+num2)} months old")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions