-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Create cc.py #111
Changes from all commits
4f38e0d
19d2c4b
b95c198
1352317
4fc29d6
4caf9f0
f9813de
33a41ae
a22a36e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: ')) | ||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
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() |
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.
Typo detected: 'Fist number:' should be corrected to 'First number:'.
Copilot uses AI. Check for mistakes.