![]() Your formulae for choices 3 and 4 are the same. Those two quantities don't really have the same units, and that made your comment() function messy. ![]() Make the distinction between calendar years and human-equivalent years clear. Can you see the bug in your code, and why I didn't use double-ended inequalities there? ![]() Note that I haven't used that feature in the comment() function, though. Python supports double-ended inequalities, like 1 <= choice <= 4. Print("You have chosen Dog -> Human and the Dog age is", input_age)Ĭhrono_age = human_equiv_age / 11 if human_equiv_age Human and the Cat age is", input_age)Ĭhrono_age = 1 if human_equiv_age = 15 else (human_equiv_age - 22) / 4 2 Human_equiv_age = 15 if chrono_age = 1 else 25 (chrono_age - 2) * 4 Human_equiv_age = 11 * chrono_age if chrono_age Cat and the Human age is", input_age) Print a remark based on the human-equivalent age.Įlif 1 Dog and the Human age is", input_age) I've removed it in the code below, and am leaving it as an exercise to you to fix it. Your "restart" feature doesn't actually work. That defeats one of the principal advantages of packaging code into functions, which is to make it clear what the inputs and outputs are for a particular chunk of code. The presence of a global variable means that a reassignment could have effects beyond the scope of a function. The use of global variables makes it difficult to understand and maintain your code. The most important kind of documentation in Python is the docstring - and you didn't write any! (Redundancy simply doubles the burden of code maintenance, as you have to ensure that your comments are consistent with the code.) Your three comments simply restate the obvious, and are therefore obnoxious or harmful. Python is a language that is designed to be easily readable. My two most important remarks concern comments and global variables. Restart = (input("Would you like to restart?(Yes or No)")).lower() Print("You have chosen to generate a random human age.") If startage Human and the Cat age is", startage) Print("You have chosen Dog -> Human and the Dog age is", startage) If startage Cat and the Human age is", startage) If choice >= 1 and choice Dog and the Human age is", startage) Print("Welcome to the animal age calculator")Ĭhoice = int(input("Which age would you like to convert?(Enter the corresponding number)\n1. #This checks if choice is equal to 1 or equal to 2 #This makes the variable startage a global variable rather than a local variable Moreover, should I comment code above or below the line of code (I have to comment as this is a requirement)? #This imports the time and random modules ![]() Could someone suggest ways to simplify this code, or any other tips? All help is much appreciated. ![]()
0 Comments
Leave a Reply. |