No construction if-elif-else



  • print("Система расчёта штрафов в Германии")
    
    carSpeed = 70
    isTown = True
    
    fineFor1to10 = 15
    fineFor11to15 = 25
    fineFor16to20 = 35
    fineFor21andMore = 80
    
    townSpeed = 60
    countrySpeed = 90
    
    if isTown:
        overSpeed = carSpeed - townSpeed
    else:
        overSpeed = carSpeed - countrySpeed
    
    if overSpeed >= 1 and overSpeed < 10:
        message_template = "You've got a fine! {des} euro!"
        message = message_template.format(des=fineFor1to10)
        print(message)
    elif overSpeed >= 11 and overSpeed < 15:
        message_template1 = "You've got a fine! {des} euro!"
        message1 = message_template1.format(des=fineFor11to15)
        print(message1)
    elif overSpeed >= 16 and overSpeed < 20:
        message_template2 = "You've got a fine! {des} euro!"
        message2 = message_template2.format(des=fineFor16to20)
        print(message2)
    elif overSpeed >21:
        message_template3 = "You've got a fine! {des} euro!"
        message3 = message_template3.format(des=fineFor21andMore)
        print(message3)
    

    It doesn't make any mistakes, but it doesn't print messages. And with the other, at the end, instead of elif, always writes only the last message.



  • You have a variable meaning. OverSpeed = 10 (70-60) No condition

    if overSpeed >= 1 and overSpeed < 10:
    

    elif overSpeed >= 11 and overSpeed < 15:

    elif overSpeed >21:

    Not implemented.

    Replace. if overSpeed >= 1 and overSpeed < 10:if overSpeed >= 1 and overSpeed <= 10:



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2