vendredi 2 mars 2018

Python: if statement prints a particular variable

I'm writing a Python exercise that calculates an average from 3 of your school subjects. After the average is calculated I want the program to find subjects that have less than 70 and print "You could improve in 'x' subject".

I know I could do it this way and write it out with specific if statements

if geometry < 70:
      print("Your geometry could be better")
elif algebra < 70: 
      print("Your algebra could be better")
etc etc

But I wondered if there was a more succinct answer, like

if geometry or algebra or physics < 70:
      print("Your", variable, "could be better")

I'm still at a beginners level of Python, is there an easier way to write out if statements and avoid those long lists?

Aucun commentaire:

Enregistrer un commentaire