Programming using Python #3 Find the errors in the following \"if\" statements:
ID: 3692246 • Letter: P
Question
Programming using Python
#3 Find the errors in the following "if" statements:
d.
xStr = input("Enter an integer value")
x = int(xStr)
if xStr.isdigit() :
sum = sum + x
else : print("Bad input for x")
#5 Suppose x and y are variables, each of which contains a number. Write a code fragment that sets y to x if x is positive and to 0 otherwise.
#6 Suppose x and y are variables, each of which contains a number. Write a code fragment that sets y to the absolute value of x without calling the abs function. Use an if statement.
Edit: for #3, sum = sum + x has an indentation to the right, meaning that it is inside the loop. I cannot indent it in the question... but everything else is exactly as it is.
Explanation / Answer
Ans;
#3 Find the errors in the following "if" statements;
d. xStr = input("Enter an integer value") x = int(xStr) if xStr.isdigit() : sum = sum + x else : print("Bad input for x") e. letterGrade = "F" if grade >= 90 : letterGrade = "A" if grade >= 80 : letterGrade = "B" if grade >= 70 : letterGrade = "C" if grade >= 60 : letterGrade = "d"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.