-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code - Sum of digits of a number #1969
code - Sum of digits of a number #1969
Conversation
Sum of digits of a number.py
Outdated
return num | ||
else: | ||
print("enter integer only") | ||
if (i-1)<=1: # if user entered wrong input, it displays a message and chances left. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use if and else.
You can use ternary operator.
Like this:
print(f"{i-1} {'chance' if i-1 == 1 else 'chances'} left")
This, does the trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NitkarshChourasia I have added this. review my code
sys.exit() | ||
while num > 0: # Addition- adding the digits in the number. | ||
digit = int(num % 10) | ||
Sum += digit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also use doc-string on the main function.
To explain it when.
print(function.__doc__ ) is used.
I have changed my code. Help me to improve this further. Needs your suggestion..... |
tomorrow morning I will review. Are you ready to take part in all of these? |
It will be basic programs, you just have to review them and provide feedback, to whatever extent you can. |
@sarayusreeyadavpadala Always tag me like this... |
Yeah ok @NitkarshChourasia |
Thanks @NitkarshChourasia Yeah! I am ready to take a part in this. |
Okay! I'll do that. @NitkarshChourasia |
Yeah, it will be a learning experience, Indeed. |
@sarayusreeyadavpadala ASK ALL YOUR FRIENDS TO PARTICIPATE FOR IT. |
return num | ||
else: | ||
print("enter integer only") | ||
print(f'{i-1} chances are left' if (i-1)>1 else f'{i-1} chance is left') # prints if user entered wrong input and chances left. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(f"{i-1} {'chance' if i-1 == 1 else 'chances'} left")
This is better readability I think.
But, your is fine, too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @NitkarshChourasia
@sarayusreeyadavpadala Congratulations. |
Thank you @NitkarshChourasia |
@sarayusreeyadavpadala Welcome. |
@geekcomputers I have added the changes to my previous code.