The input is a list of strings, add code below it (and fix indentation and variable names if needed) so that the code wi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

The input is a list of strings, add code below it (and fix indentation and variable names if needed) so that the code wi

Post by answerhappygod »

The Input Is A List Of Strings Add Code Below It And Fix Indentation And Variable Names If Needed So That The Code Wi 1
The Input Is A List Of Strings Add Code Below It And Fix Indentation And Variable Names If Needed So That The Code Wi 1 (82.35 KiB) Viewed 30 times
code;
# create the input
input = ["Pat,Smith,girl,65 Elm Street,eat", "John,Doe,Boy,25,123
Candy Lane, tickle"]
# split at the comma
pieces = input.split(",")
# initialize the variables
firstName = pieces[0]
lastName = pieces[1]
gender = pieces[2]
address = pieces[3]
verb = pieces[4]
# create the story
start = "Once there was a " + gender + " named " + firstName +
"."
next1 = "A good " + gender + " living at " + address + "."
next2 = "One day, a wicked witch came to the " + lastName + "
house."
next3 = "The wicked witch was planning to " + verb + " " +
firstName + "!"
ending = "But " + firstName + " was smart and avoided the wicked
witch."
# print the story
print(start)
print(next1)
print(next2)
print(next3)
print(ending)
The input is a list of strings, add code below it (and fix indentation and variable names if needed) so that the code will print a story for each string in the list. Save & Run Load History = 1 # create the input 2 input = ["Pat, Smith, gir1,65 Elm Street, eat", "John, Doe 3 4 # split at the comma 5 pieces input.split(",") 6 7 # initialize the variables 8 firstName = pieces[0] 9 lastName = pieces[1] 10 gender = pieces [2] 11 address = pieces [3] 12 verb = pieces [ 4 ] 13 14 # create the story 15 start = "Once there was a + gender + named + fire 16 nexti "A good + gender + " living at " + address + 17 next2 = "One day, a wicked witch came to the + lastne 18 next3 = "The wicked witch was planning to " + verb + 19 ending = "But + firstName + " was smart and avoided 20 21 # print the story 22 print (start) 23 print(next1) 24 print(next2) 25 print (next 3) 26 print(ending) 11 + 11 1 27
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply