I help software development and IT operations adopt NoSQL databases. In a previous avatar, I was technofunctional ERP consultant & built custom applications to extend the functionality of ERP systems.
Location
Dubai
Work
Software Development and Database Consultant at Dubai
Kudos to you for progressing so much in only 3 days!
On the first line of your program, where you are converting the input into an integer, consider adding a check for isnumeric(). The reason for this is if the user enters invalid input (Eg. an alphabet), the program will exit with a ValueError exception. You will most likely learn about exception handling later.
Here's an example:
input_text = input('Enter a number')
if input_text.isnumeric():
#write your logic here
pass
else:
print('The input was invalid')
You can take the input check further - if the user enters a decimal number, converting the input to an integer will fail with a ValueError exception.
I help software development and IT operations adopt NoSQL databases. In a previous avatar, I was technofunctional ERP consultant & built custom applications to extend the functionality of ERP systems.
Location
Dubai
Work
Software Development and Database Consultant at Dubai
UPDATE: I searched and found a ".isdigit()" method for strings which helps check if the string contains a positive integer. You can use ".isdigit()" instead of ".isnumeric()".
To allow negative numbers (Eg. when the electric company is unable to get the meter reading and uses an average-unit-count to bill you for the month, the next number of units can be in the negative), you can use an "or" in the condition with input_text.starts_with("-") and input_text[1:].isdigit()
Kudos to you for progressing so much in only 3 days!
On the first line of your program, where you are converting the input into an integer, consider adding a check for isnumeric(). The reason for this is if the user enters invalid input (Eg. an alphabet), the program will exit with a ValueError exception. You will most likely learn about exception handling later.
Here's an example:
You can take the input check further - if the user enters a decimal number, converting the input to an integer will fail with a ValueError exception.
Thank you for suggestion
UPDATE: I searched and found a ".isdigit()" method for strings which helps check if the string contains a positive integer. You can use ".isdigit()" instead of ".isnumeric()".
To allow negative numbers (Eg. when the electric company is unable to get the meter reading and uses an average-unit-count to bill you for the month, the next number of units can be in the negative), you can use an "or" in the condition with input_text.starts_with("-") and input_text[1:].isdigit()
Thank you for sharing.