WILL UPVOTE!! Question 7 2.5 pts Consider the following Python code x=\"1\" y=10
ID: 3915343 • Letter: W
Question
WILL UPVOTE!!
Question 7 2.5 pts Consider the following Python code x="1" y=10 Which of the following will produce an error when executed? print(x+stry print(x +y) print(str(x) +st(y)) print(int(x)+ float(y) Question 8 2.5 pts The function convert_to_grade takes in a number and returns the corresponding letter grade. The function convert to text takes in a letter grade and returns a string that contains words of encouragement based on the letter grade. Which of the following is used to get some words of encouragement for someone whose score is stored in the variable x? print(convert to _text(convert to_grade(x)) print(convert_to_grade(convert to_letter(x) print(convert to text(x)) print convert_to_grade((convert to_grade(x)) print convert to_text((convertto text(x))Explanation / Answer
1. print(x + y)
Explanation:
print(x + y) will throw an error: TypeError: must be str, not int
This is because x is of type str whereas y in int. In this case, + operator is used for string concatenation, hence it expects y to be a string too. Hence we would need to explicitely change the type of 'y' to string, as shown below:
print(x + str(y))
2. a) print(convert_to_text(convert_to_grade(x))
Explanation: Self explanatory.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.