Skip to content

Create cc.py #111

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions calc/cc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from operator import add, sub, mul

def calc():
op = input("Enter operator +-*: ")
n1 = int(input('Fist number: '))
Copy link
Preview

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo detected: 'Fist number:' should be corrected to 'First number:'.

Suggested change
n1 = int(input('Fist number: '))
n1 = int(input('First number: '))

Copilot uses AI. Check for mistakes.

n2 = int(input('Second number: '))
operators = {'+': add(n1, n2), '-': sub(n1, n2), '*': mul(n1, n2)}
if op in operators:
print('{} {} {} = {}'.format(n1, op, n2, operators[op]))
Comment on lines +7 to +9
Copy link
Preview

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The dictionary currently precomputes all operations regardless of the selected operator. Consider mapping operator symbols to the corresponding function (e.g., {'+': add, ...}) and then computing the result after determining the operator to improve efficiency and consistency.

Suggested change
operators = {'+': add(n1, n2), '-': sub(n1, n2), '*': mul(n1, n2)}
if op in operators:
print('{} {} {} = {}'.format(n1, op, n2, operators[op]))
operators = {'+': add, '-': sub, '*': mul}
if op in operators:
result = operators[op](n1, n2)
print('{} {} {} = {}'.format(n1, op, n2, result))

Copilot uses AI. Check for mistakes.

input('Press enter to return menu\n')

def menu():
while True:
print('(1) Calculate 2 numbers')
print('(Q) Quit')
choice = input('Enter your choice: ').lower()
if choice == '1':
calc()
elif choice == 'q':
return False
else:
print('Not a correct choice: <{}>,try again'.format(choice))

if __name__ == '__main__':
menu()
Loading