Question

Please help me with this problem below What is wrong with the following code? if income...

Please help me with this problem below

What is wrong with the following code?

if income < 20000:

tax = .05

elif income >=20000:

tax = .10

elif income >=50000:

tax = .15

Would the answer be that the last elif statement is not needed. Therefore the fixed answer would be:

if income < 20000:

tax = .05

elif income >=20000:

tax = .10

else:

tax = .15

??

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

The problem in the above code is last elif income >=50000:   will be dead code, ie it wont be satisfied for any of the input as previous elif income >=20000: condition get satisfied if the income is more than 20000.

                Similarly for the second code last else: condition wont work .

If you want to add the condition to check if income >=50000: then do as follows

if income < 20000:

              tax = .05

elif income >=20000 and income<50000:

                 tax = .10

else:

                 tax = .15

Add a comment
Know the answer?
Add Answer to:
Please help me with this problem below What is wrong with the following code? if income...
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
  • Please help me correct the wrong answer. If you could also tell me what I did...

    Please help me correct the wrong answer. If you could also tell me what I did wrong that would be fantastic, thank you! 10. (2 pts) Draw the structure of the transition state for the following reaction: C + H, at 0lt2

  • this code below is not the full code. I need help outputting both first name and...

    this code below is not the full code. I need help outputting both first name and last name. Can you please fix my code. I use getline but it says sometthing is wrong with my if statement our whatever cout<<" -=| ADDING STUDENT |=-" << endl; cout<<"Please enter the student’s name: "; cin>>s_name; if(g.add_std(s_name)) cout<<"\n"<<s_name<<" was successfully added to the gradebook!"; else cout<<"\nStudents cannot be added because the gradebook is full!"; break;

  • hello good night, could you help me to see what is wrong with my code, two...

    hello good night, could you help me to see what is wrong with my code, two errors appear at the bottom in red: In [47]: file_contents-open("color-blanco.png") def calculate_frequencies (file_contents): # Here is a list of punctuations and uninteresting words you can use to process your text punctuations = ""!()-[]{};:"",-./?@#$%^&*_~ uninteresting_words = ["the","in" ,"a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", "we", "o # LEARNER CODE START HERE result={} a-file_contents.split() for word in a: if word...

  • What is the below code attempting to do (continuing from previous part)? What is wrong with this ...

    C++ We were unable to transcribe this imageWhat is the below code attempting to do (continuing from previous part)? What is wrong with this approach? How would you fix this? n- head; while(n)\ if(n->data == 2) { delete n; n = n-> next; else\ n = n->next; What is the below code attempting to do (continuing from previous part)? What is wrong with this approach? How would you fix this? n- head; while(n)\ if(n->data == 2) { delete n; n...

  • Hello, I need someone to help me solving this problem, please. ================ For the code sequence...

    Hello, I need someone to help me solving this problem, please. ================ For the code sequence below: add $1, $2, $3 sub $4, $1, $5 and $6, $1, $7 or $8, $1, $9 xor $4, $1, $5 1) Draw the pipelined dependences. 2) Show the forwarding paths needed to resolve the data hazards.

  • At least one of these answers are wrong (probably more). Please help me correct this problem....

    At least one of these answers are wrong (probably more). Please help me correct this problem. In each of the following cases, calculate the accounting break-even and the cash break-even points. Ignore any tax effects in calculating the cash break-even. (Do not round intermediate calculations. Round your answers to 2 decimal places, e.g., 32.16.) Case Unit Price 1 $ 3,310 2 136 Unit Variable Cost $ 2,635 77 7 Fixed Costs $ 9,120,000 49,000 3,500 Depreciation $3,700,000 330,000 990 3...

  • Please help me correct the wrong answer. If you could also tell me what I did...

    Please help me correct the wrong answer. If you could also tell me what I did wrong that would be fantastic, thank you! 6. (8 pts) into how many peaks will the 'HNMR signal for each of the indicated protons! be split? Ha H HC Ha Ha H6 (CH2),CHC CH CH.CH,CH, OH OCH,CH, *2160

  • Please help me correct the wrong answer. If you could also tell me what I did...

    Please help me correct the wrong answer. If you could also tell me what I did wrong that would be fantastic, thank you! 8. (5 pts) For the following compound, state how many 1H NMR signals are present, and the splitting pattern for each signal. Be sure to indicate which proton(s) give rise to which signals. Ha Hb Hb Ha CH3CH2 CH2CH3 He c= 3 signals Htc Ha= triplex v Ho= quintet & 4 = triplet v

  • Accounting Help. Thanks! I don't know what I'm doing wrong, please help me find the correct...

    Accounting Help. Thanks! I don't know what I'm doing wrong, please help me find the correct answers for everything marked wrong Exercise 6-4 * Your answer is incorrect. Try again. Comfi Airways, Inc., a small two-plane passenger airline, has asked for your assistance in some basic analysis of its operations. Both planes seat 10 passengers each, and they fly commuters from Comfi's base airport to the major city in the state, Metropolis. Each month 40 round-trip flights are made. Shown...

  • could you please show me what I am doing wrong in the Javascript code below. <html>...

    could you please show me what I am doing wrong in the Javascript code below. <html>   <head> <meta charset="UTF-8"> <title></title> <style> #mytext { color: white; text-align: center; } </style> <script> var words = "The cat sat on the mat"; document.writeln("id='mytext"+ words '); </script>   </head>   <body>   </body> </html>

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