dimanche 23 avril 2017

An alternative to many if-statements?

So I have 3 different variables.

model which is a string and defines the iPhone model.

storage which is a integer that defines the phones storage.

And finally price, which is an integer that defines the price of the phone.

Example:

model = iPhone 7
storage = 64 (GB)
price = 700 ($)

Another example:

model = iPhone 5s
storage = 16
price = 150

Now I want my program to notify me if I can make a good deal by buying and reselling, and my question is how do I do that in the most efficent way?

I know that I can use if statements, but is there any method to save me from writing alot diffrent if or elif statements?

Example:

if model == "iPhone 7" and storage == 64 and price == 700:
print("do_something")

That's alot of code for just 1 model and storage option. If I would be using this method i'd have to write 29 more.

Aucun commentaire:

Enregistrer un commentaire