Python Forum
Interesting Intro to python problem I can't solve.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interesting Intro to python problem I can't solve.
#4
I'm a lot older than 48 and I am doing homework right now. I figure I'll stop doing homework a few minutes before I stop breathing.

Your "effort" crashes because flag is only defined when the age entered < 0.

I would replace this:
if dog_age < 0 :
    flag = True
with
if dog_age < 0:
    raise ValueError
You already have an exception handler, you may as well use it.

You can also simplify the comparisons and your math:
        if dog_age < 0 :
            raise ValueError
        elif dog_age <= 1 :
            dog_age_in_Human_years = dog_age * 15.0
        elif dog_age <= 2 :
            dog_age_in_Human_years = dog_age * 12.0
GOTO10 likes this post
Reply


Messages In This Thread
RE: Interesting Intro to python problem I can't solve. - by deanhystad - Feb-26-2021, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to solve this problem Python configuration? magomes 5 4,814 Mar-22-2024, 11:11 PM
Last Post: magomes
  Two Python problems to solve djzsp 1 1,204 Mar-17-2024, 01:18 AM
Last Post: deanhystad
  How to solve pancake flip with Python longmen 5 3,368 May-09-2022, 05:16 PM
Last Post: deanhystad
  How to solve problem 1181 of the URI with numpy. thiagohps 4 3,718 Mar-22-2021, 04:11 PM
Last Post: buran
  solve probability problem by python Dreammer 1 2,435 Dec-24-2020, 09:51 AM
Last Post: Larz60+
  Intro python using lists Rustypotatoes 2 5,417 Sep-17-2020, 08:30 PM
Last Post: jefsummers
  An interesting Role-Play-Game battle script NitinL 4 4,427 Apr-02-2020, 03:51 AM
Last Post: NitinL
  Algorithm to solve a case of Travelling Salesman Problem Ale888 3 4,013 Dec-11-2018, 07:49 PM
Last Post: buran
  Cross word puzzle solve using python constraint library aliyark145 1 4,038 Nov-29-2018, 10:53 AM
Last Post: Larz60+
  Intro to Python for Data Science with Datacamp Sabrusura 4 4,606 Aug-21-2018, 09:03 AM
Last Post: Sabrusura

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020