Skip to content

Conversation

AkhilYadavPadala
Copy link

@AkhilYadavPadala AkhilYadavPadala commented Oct 6, 2023

@OfficialAhmed @NitkarshChourasia
I made changes.
Review my code :)

@NitkarshChourasia
Copy link
Contributor

I will do by the morning afternoon of 7th October, 2023.

Copy link
Contributor

@OfficialAhmed OfficialAhmed left a 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

Copy link
Contributor

@NitkarshChourasia NitkarshChourasia left a 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))
Copy link
Contributor

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.

# This function adds two numbers
def add(x, y):
return x + y
class Calculator:
Copy link
Contributor

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")
Copy link
Contributor

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.

@AkhilYadavPadala
Copy link
Author

I made corrections on indentation @OfficialAhmed .
Thanks for the suggestion @NitkarshChourasia . I used black command to do so

@NitkarshChourasia
Copy link
Contributor

I made corrections on indentation @OfficialAhmed .
Thanks for the suggestion @NitkarshChourasia . I used black command to do so.

Welcome.

@geekcomputers geekcomputers merged commit 99f3900 into geekcomputers:master Oct 8, 2023
@AkhilYadavPadala
Copy link
Author

@geekcomputers Would you mind adding hacktoberfest and hacktoberfest-accepted labels to my pull request.

@NitkarshChourasia
Copy link
Contributor

This repo has not been added to that program-fest. @AkhilYadavPadala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants