Question

(5%) Explain why in Python, writing a multiple selection using else-if clauses (elif) is more readable than using nested if then-else statements. Use some Python code to illustrate your answer.

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

Explanation: Nested if else condition is more readable that if else statement. When you have a multiple conditions to choice any one of them then we have to use nested if else conditions. When you have only two conditions and either of them should execute means we have to use if else statement.

score = int(input("Enter the score: "))
grade = ''
if score >= 90:
grade = 'A'
elif score >= 80 and score < 90:
grade = 'B'
elif score >= 70 and score < 80:
grade = 'C'
elif score >= 60 and score < 70:
grade = 'D'
else:
grade = 'F'
  
print("Grade is ", grade)

Output:

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

Enter the score: 77                                                                                                                                                                                                                                                    

Grade is  C

Execute >share Code main.py x 1 score int(input (Enter the score:)) 2 grade= 3 if score > 90: grade A grade B grade

Add a comment
Know the answer?
Add Answer to:
Explain why in Python, writing a multiple selection using else-if clauses (elif) is more readable than...
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
  • Use python and use if, elif and else statements. Thank you! The program should first ask...

    Use python and use if, elif and else statements. Thank you! The program should first ask the user if they are a hero or a villain. If they enter “villain”, the program should ask them their name; if they enter “hero”, it should ask how many people they have saved, and respond to that information. Using decision structures, have your program execute certain print statements following these rules: If they enter that they are a villain Ask for their name...

  • Hi I need some help writing a security code using python mongodb restful api. I just...

    Hi I need some help writing a security code using python mongodb restful api. I just need help on how to provide a security login to user to enter their username and password or to have a block in using extra access once they have logined and they want more access to the databases they will be force to sign out of the server but I just do not know how to start on it can someone show me how...

  • Hello, I am trying to solve the following problem using python: Assignment 3: Chatbot A chatbot...

    Hello, I am trying to solve the following problem using python: Assignment 3: Chatbot A chatbot is a computer program designed to emulate human conversation. For this program you will use if statements, user input, and random numbers to create a basic chatbot. Here is the scenario: You have decided to start an online website. You are creating a prototype to show investors so you can raise money and launch your website. You should ask the user at least 5...

  • D 26. Why do we expect to see more synonymous substitutions than non-synonymous substitutions if a...

    D 26. Why do we expect to see more synonymous substitutions than non-synonymous substitutions if a locus is under purifying selection? In your answer, be sure to explain what synonymous vs. non-synonymous substitutions and purifying selection are. Enter answer... D27 In some birds such as phalaropes, males provide all of the parental care to offspring, and females compete with one another for access to males and breeding territory. In this species, would you expect males or females to be larger...

  • Which are true of Selection Sort? please explain Multiple answers:You can select more than one option...

    Which are true of Selection Sort? please explain Multiple answers:You can select more than one option A) It uses Θ(n^2) comparisons in the worst case B) It uses Θ(n^2) comparisons in the average case C) It uses Θ(n^2) comparisons in the best case D) It uses Θ(n^2) swaps in the worst case E) It uses Θ(n^2) swaps in the average case F) It uses Θ(n^2) swaps in the best case

  • Search 12:40 pm Wed 13 Mar C Get Homework Help With c × Th| Assessment-CSSE1001 S...

    Search 12:40 pm Wed 13 Mar C Get Homework Help With c × Th| Assessment-CSSE1001 S × D https://mytut2.uqcloud.net × + 3 a mytut2.uqcloud.net Due: 20:30 15th Mar ﹀ [CSSE1001/7030] Introduction to Software Engineering (St Lucia) Semester 1, 2019-(4/43) completed if sign 2019 Save Attempt Reset Attempt Run Code 2 int string input('7 3 x--int (int_string) Week 2: Introductory Programming - (3/3) completed If Statements Using Elif and Else print( "monty" elif x-7 print( python) elif x 3: print( 'flying')...

  • Please help me code the following in: JAVA Please create the code in as basic way...

    Please help me code the following in: JAVA Please create the code in as basic way as possible, so I can understand it better :) Full points will be awarded, thanks in advance! Program Description Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can...

  • why are benzene rings more stable than alkenes? use diagrams to explain your answer

    why are benzene rings more stable than alkenes? use diagrams to explain your answer

  • Why do we expect to see more synonymous substitutions than non-synonymous substitutions if a locus is...

    Why do we expect to see more synonymous substitutions than non-synonymous substitutions if a locus is under purifying selection? In your answer, be sure to explain what synonymous vs. non- synonymous substitutions and purifying selection are. : BIU A - A - Ix E 3 MB NVX 6 0 3 3 x © All x 12pt HTML Editora = - Paragraph - O words Question 27 2 pts In some birds such as phalaropes, males provide all of the parental...

  • Carbon dioxide is non-polar, despite the fact that oxygen is much more electronegative than carbon. Briefly...

    Carbon dioxide is non-polar, despite the fact that oxygen is much more electronegative than carbon. Briefly explain why, using relevant diagrams as appropriate to illustrate your answer.

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