Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[8] 7. What is printed by this Python code? Answer: printl\' is (:.1f)i\'.format

ID: 3895613 • Letter: #

Question

[8] 7. What is printed by this Python code? Answer: printl' is (:.1f)i'.format('It', 3.159)) [12]8. What is printed by this Python code? Answer: #1 #2 #3 #4 #5 #6 x2 for k in [5, 1, 3]: print (t) [6] 9. What is printed by this Python code? Answer d ['L' ] = 'LEFT. d [ R' ] = RIGHT. print ('{L?, {R}, {L}! format (**d)) - [8] 10. Add one line of Python code to make the dictionary myData have an entry with key 'name' and value 'Erin' [11] 11. Consider program output I am happy I am excited I am waiting Write a for-statement heading before the for-statement body that is already written below, so the for- statement produces the output above # your heading am' , word) [15] 12. Write Python code to prompt the user to enter a word at the keyboard, and then to enter a number of repetitions. Then print the specified string repeated the specified number of times. The code should be able to produce interactive sessions like the illustrations at the left and right below. (User responses are shown in bold italics) Enter a word: hi Number of repetitions: 3 Enter a word: bye Number of repetitions: 2 bvebze

Explanation / Answer

[8] 7. The output is :

Reason being new formatting style is used. {} stands for a value and then "is" is printed with another value from {} and an exclamation mark. The second value is formatted to have 1 integer after decimal point. So the first value of {} is "It" as provided by format function's first argument. The second float to be formatted is 3.159 which is rounded to one decimal point since we have specified 1f - 1 element.

[12] 8. The output is:

Reason being, in every iteration of for loop we compute t = t + x*k for values mentioned in k - 5,1,3. The value in t is printed on new line evrytime and we increment x everytime.

Values of variables in every iteration

[6] 9. The output is :

Reason being, to we are referring to dictionary d's values. To unpack the dictionary into keyword values we use ** in the format function. So the corresponding value of keys mentioned in the print function get displayed alon with commas in between and exclamation as it is given in format string.

[8] 10. Line of code to be added is :

myData['name'] = 'Erin'

This will add key 'name' in myData with value as 'Erin'

[11] 11. The for heading required is a list of string which are given in output so the heading is:

for word in ['happy','excited','waiting']:

print('I am',word)

In every iteration of for loop, one value from the list is picked and displayed. so the iutput is as mentioned in the question.

[15] 12. #input method is used for taking input from user, it'll always take input in string format

#We need to convert num to integer since input function takes input in string format, added 1 to it since range function doesn't include the last value mentioned

#We have used end = ' ' to display all values in one line otherwise by default it'll display values on newline

name = input("Enter a word ")

num = input("Number of repetitions")

for i in range(1,int(num)+1):

print(name,end='')

Iteration k x t = t+x*k 1 5 1 3 + 1*5 = 8 2 1 2 8 + 1*2 = 10 3 3 3 10 + 3*3 = 19
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote