lundi 15 novembre 2021

How do you make a correct IF statement with intervals, in Python?

I've recently started a course that is solely about Python through my school. I'm a complete beginner as of today, and i just recived my first task.

Using Python 3.10.0

The task was as follows: Pretend that you're a merchant that buy cars. A customer comes in and offers three cars for sale.

  1. Collect the following information. What brand is the car, class, year and how many miles has it driven.
  2. Now make a program that summarizes the information you gathered. As far as i have debugged in Microsoft VSC i've solved this in my own way, probably can be done in a much better way i assume though.. --

Though the task is graded based on how many functions or variabels you're using, the more the better in this case accordlingy to the teacher. So i figured, why not try to make some sort of price range based on what the seller offered/answered in interval types. Depending on what the customer gives for information regarding year and miles, in the end of this made up conversation, an automated evaluated price will be presented for all three cars based on given information.

So my question is, am i right to use the IF statement in the end of my code, if so what am i doing wrong, or isit a another solution to this?

Best Regards :)


q1 = input("What's the first car you'd like to offer? ")
print("Awesome! A " + q1)
q2 = input("What class is it? ")
print("Great.")
q3 = input("Year? ")
q4 = input("And lastly, how many miles have the car driven? ")

q5 = input("What's the second car you'd like to offer? ")
print("Awesome! A " + q5)
q6 = input("What class is it? ")
print("Great.")
q7 = input("Year? ")
q8 = input("And lastly, how many miles have the car driven? ")

q9 = input("What's the third car you'd like to offer? ")
print("Awesome! A " + q9)
q10 = input("What class is it? ")
print("Great.")
q11 = input("Year? ")
q12 = input("And lastly, how many miles have the car driven? ")

#Verbal summary of the offered cars.
print()
print("So we have a " + q1, "model " + q2, "year " + q3, ",that has driven " + q4, "miles.")
print("And a " + q5, "model " + q6, "year " + q7, ",that has driven " + q8, "miles.")
print("Lastly we have the cool " + q9, "model " + q10, "year " + q11, ",that has driven " + q12, "miles.")

#Calculation/Evaluation.
year_question_intervall_type_1 = 1900-1930
year_question_intervall_type_2 = 1931-1950
year_question_intervall_type_3 = 1951-1980
year_question_intervall_type_4 = 1981-2000
year_question_intervall_type_5 = 2001-2021

miles_question_interval_type_1 = 100-1000
miles_question_interval_type_2 = 1001-2000
miles_question_interval_type_3 = 2001-5000
miles_question_interval_type_4 = 5000-8000
miles_question_interval_type_5 = 8001-100000

#Price offer to seller.

if q3 == year_question_intervall_type_1: 
    print("9999 Dollars")

Aucun commentaire:

Enregistrer un commentaire