Oct-10-2018, 05:40 AM
Hi, thanks a lot for replying - it helps me already quite a lot^^
I would have 2 questions as for your code:
1.) Regards to the first line: 'How on earth python knows what 'attempts' are?
My guess, it cannot know it and it does not matter, since due to the range() methode it will just iterate 5 times, whatever the keyword is, right?
2.) the output of your code after 5 iterations does look like that:
I would have 2 questions as for your code:
1.) Regards to the first line: 'How on earth python knows what 'attempts' are?
My guess, it cannot know it and it does not matter, since due to the range() methode it will just iterate 5 times, whatever the keyword is, right?
2.) the output of your code after 5 iterations does look like that:
Output:Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:/Users/kr-ga/AppData/Local/Programs/Python/Python37-32/BOOK_automate_the/Chapter 6/test.py
Enter your age:
hs
Please enter a number for your age.
Enter your age:
sh
Please enter a number for your age.
Enter your age:
hs
Please enter a number for your age.
Enter your age:
hs
Please enter a number for your age.
Enter your age:
sh
Please enter a number for your age.
Traceback (most recent call last):
File "C:/Users/kr-ga/AppData/Local/Programs/Python/Python37-32/BOOK_automate_the/Chapter 6/test.py", line 7, in <module>
raise Exception('Wrong age in 5 attempts')
Exception: Wrong age in 5 attempts
>>>
Can we somehow change the code, so that python prints ot fpr the user a nice message, such as 'Sorry, too many attempts' before breaking with an 'ugly' error-message after 5 falied attempts?