Question

TU. . IVIL main.py Load default template... 1 # Read a list of strings from the user 3 def square(x): return x*x nmin on inp1: Compare output ^ 0/1 Output differs. See highlights below. Input 1 2 3 4 Your output Expected output [1, 4, 9, 16] 2: Comp

can someone please tell me where did I do wrong and how I can fix this

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

There is only one issue with the code and that is the way you are printing the result, you are using :-

for i in result:
print(i)

It prints i (value in the result) and then moves to next line. and so on.

Instead you should only use :- print(result) in place of for loop, this will print result in form of a list.

I have edited the code and commented where the code needs to be changed.

Code:-

def square(x):
return x*x
  
input_string = input()
numbers = []
for i in (str(input_string)):
numbers.append(i*2)
  
numbers = [int(i) for i in input_string.split()]
result = list(map(lambda x: x*x, numbers))

# you should use this instead of for loop
print(result)

- def square(x): return xx input_string = input() numbers = [] for i in (str(input_string): numbers.append(i*2) numbers = [in

Output:-

1234 [1, 4,9,16]

Hope it clears your doubt, do comment in case of any other doubt.

Please up vote if it helps you :)

Add a comment
Know the answer?
Add Answer to:
can someone please tell me where did I do wrong and how I can fix this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python and can you tell me why i am wrong? Thank you ZyBooks Python M...

    in python and can you tell me why i am wrong? Thank you ZyBooks Python M X zy cS 171: Computer x zy 11.9. LAB: Output x C Write A Program 1 x Slack | Hiu Nguy TG Python Program t x p ython - Getting x +. - 5 x € → e l earn.zybooks.com/zybook/DREXELCS171 Winter2020/chapter/11/section/9 Help/FAQ Kuanyu Lai - = zyBooks Bake My library > CS 171: Computer Programming home> > 11.9: LAB: Output values in a list...

  • I dont know what I did wrong but I got 9/10. I need one more. Computer...

    I dont know what I did wrong but I got 9/10. I need one more. Computer Sciencés Role in Industry home > 4.10: Program Automobile service invoice (Python 3) E zyBooks catalo 4.10 Program: Automobile service invoice (Python 3) (1) Output a menu of automotive services and the corresponding cost of each service.(2 pts) Ex: Davy's auto shop services oil change $35 Tire rotation $19 Car wash$7 Car wax $12 (2) Prompt the user for two services from the menu....

  • I dont know what I did wrong but I got 9/10. I need one more. Computer Sciencés Role in...

    I dont know what I did wrong but I got 9/10. I need one more. Computer Sciencés Role in Industry home > 4.10: Program Automobile service invoice (Python 3) E zyBooks catalo 4.10 Program: Automobile service invoice (Python 3) (1) Output a menu of automotive services and the corresponding cost of each service.(2 pts) Ex: Davy's auto shop services oil change $35 Tire rotation $19 Car wash$7 Car wax $12 (2) Prompt the user for two services from the menu....

  • Code in C++ please 9.13 Review: Branches: Next date Many websites let users make reservations (hotel,...

    Code in C++ please 9.13 Review: Branches: Next date Many websites let users make reservations (hotel, car, flights, etc.). When a user selects a date, the next day is often automatically selected (for hotel checkout, car return, flight return, etc.). Given a date in the form of three integers, output the next date. If the input is 1 15 2017, the output should be 1 16 2017. If the input is 8 31 2017, the output should be 9 1...

  • How do I add the space that this Zybooks code keeps asking me to add? 5.13...

    How do I add the space that this Zybooks code keeps asking me to add? 5.13 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5...

  • can someone tell me what i did wrong ? A high-speed lifting mechanism supports a(n) 700-kg...

    can someone tell me what i did wrong ? A high-speed lifting mechanism supports a(n) 700-kg object with a steel cable that is 36.0 m long and 4.00 cm? in cross-sectional area. (a) Determine the elongation of the cable. (Enter your answer to at least two decimal places.) 3.9 х Your response differs from the correct answer by more than 10%. Double check your calculations, mm (b) By what additional amount does the cable increase in length if the object...

  • I want to know how to do this assignment!!! Help me please~ The first part of...

    I want to know how to do this assignment!!! Help me please~ The first part of your program should do the following: • Ask the user type of test they took. o (ACT or SAT) • If they said ACT then ask them their score o If their ACT score was between 0 and 7 say "Needs Work" o If their ACT score was between 10 and 20 say "Acceptable" o If they ACT score was above 20 say "Above...

  • I can't figure out which part of this assignment I am getting wrong. Any help would...

    I can't figure out which part of this assignment I am getting wrong. Any help would be appreciated thank you. A cashier distributes change using the maximum number of five-dollar bills, followed by one-dollar bills. Write a single statement that assigns num_ones with the number of distributed one-dollar bills given amount_to_change. Hint: Use %. Sample output with input: 19 Change for $ 19 3 five dollar bill(s) and 4 one dollar bill(s) amount_to_change = int(input) WNE 1 test passed 3...

  • Can someone please check and tell me what I did wrong, please and thank you. 7....

    Can someone please check and tell me what I did wrong, please and thank you. 7. Explain what this result means in words. Price elasty of demand for Cereal is Suppose that a store decreases the price of laundry detergent from $4.10 to $3.50. As a result, quantity demanded increases from 210 to 230. 8. Using the mid-point approach, calculate the percentage change in price. I This assignment by Lumen Learning is licensed under a Creative Commons Attribution 4.0 Elasticity...

  • HOW DOES THE CODE WORK AND PLEASE TELL ME WHERE DID THE NUMBER [J] COME FROM...

    HOW DOES THE CODE WORK AND PLEASE TELL ME WHERE DID THE NUMBER [J] COME FROM WHEN IT HASN'T BEEN DECLARED IN THE ABOVE STATEMENT MOREOVER KINDLY ALSO DRY RUN THE PROGRAM TO MAKE IT MUCH EASIER TO UNDERSTAND int main() { int i, j, a, n, number[i]; printf("Enter the value of N \n"); scanf("%d", &n); printf("Enter the numbers \n"); for (i = 0; i < n; i++) scanf("%d", &number[i]); for (i = 0; i < n; ++i) { for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT