-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Gc #1994
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
Gc #1994
Conversation
I will do by the morning afternoon of 7th October, 2023. |
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.
- Improper indentation from line 86 to 101 .Probably it won't interpret the code properly remove indentation.
- In line 99
break
keyword is also indented incorrectly
Double check the indentation please, the rest of the code works fine
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.
Everything is perfect, just minor corrections and you are good to go.
|
||
elif choice == '2': | ||
print(num1, "-", num2, "=", subtract(num1, num2)) | ||
print(calculator.subtract(num1, num2)) |
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.
Use a IDE if possible while coding.
Also, Use a code formatter if possible.
If possible, enable code formatter when saving the file.
You can also format the code by black
.
to install just type in cmd pip install black
then format the file using cmd by typing in cmd black file_name.py
and worry not, there are many ways to format a file. This clicks with me, that's it.
Calculator with simple ui.py
Outdated
# This function adds two numbers | ||
def add(x, y): | ||
return x + y | ||
class Calculator: |
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.
Can add a docsting for class, here...too.
|
||
|
||
print("Select operation.") | ||
print("1.Add") | ||
print("2.Subtract") |
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.
calculator = Calculator()
# A dictionary that maps the choices to the functions
operations = {
"1": calculator.add,
"2": calculator.subtract,
"3": calculator.multiply,
"4": calculator.divide
}
# A loop that asks the user for input until they enter a valid choice
while True:
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
choice = input("Enter choice(1/2/3/4): ")
# Check if the choice is valid
if choice in operations:
# Ask the user for two numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Get the function by its key from the dictionary
operation = operations.get(choice)
# Call the function with the two numbers and print the result
result = operation(num1, num2)
print(f"The result is {result}")
# Break out of the loop
break
else:
# Print an error message and continue the loop
print("Invalid input. Please try again.")
Understand these snippet.
I made corrections on indentation @OfficialAhmed . |
Welcome. |
@geekcomputers Would you mind adding hacktoberfest and hacktoberfest-accepted labels to my pull request. |
This repo has not been added to that program-fest. @AkhilYadavPadala |
@OfficialAhmed @NitkarshChourasia
I made changes.
Review my code :)