Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ This repository will contain basic python programming questions and their soluti
- Please run the program and check if there are no errors before making the PR
- Review other PR's as well
- No Spamming allowed, make sure to include all programs in one PR.
- This is my first contribution on Github
- Add a new program which convert the integer number in words
8 changes: 8 additions & 0 deletions adding_error_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try:
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
num3 = int(input("Enter Third Number: "))
print("The sum of the three numbers is:", num1 + num2 + num3)
except ValueError:
print("Invalid input! Please enter valid integers only.")
exit()
28 changes: 28 additions & 0 deletions number_to_word_convertor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# In this program we will convert numbers to words
# For example: 123 -> One Two Three
def number_to_words(number):
# Define a mapping of digits to words
digit_to_word = {
'0': 'Zero',
'1': 'One',
'2': 'Two',
'3': 'Three',
'4': 'Four',
'5': 'Five',
'6': 'Six',
'7': 'Seven',
'8': 'Eight',
'9': 'Nine'
}
result=[]
# Convert the number to string to iterate over each digit
for digit in str(number):
if digit in digit_to_word:
result.append(digit_to_word[digit])
else:
return "Invalid input! Please enter a valid non-negative integer."
return ' '.join(result)
# Example usage
if __name__ == "__main__":
number = int(input("Enter a non-negative integer: "))
print("Number in words:", number_to_words(number))