Computer Science, asked by ishikarana249, 3 days ago

compare and contrast efficiency of nested if-else and switch case by an example. ​

Answers

Answered by yashsinhtgb
2

Answer:

Switch case is best for long condition based events

Explanation:

For example:

if-else:

age = 18

if age < 10:

print ("You are a kid")

elif age == 18:

print("You are not big enough to earn money yet")

elif age > 20:

print("still in college?")

elif age > 30:

print("earn some money lol")

switch case:

age = 18

switch:

case age < 10:

print("kiddo :)")

case age == 18:

print("You can drive my car now :)")

case age > 20:

print ("still in college")

case age > 30:

print("Earn some money >:(. ")

Similar questions