From 7f67a6bd5c5a8371654f22f7bf85f41634a585c3 Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 1 Jun 2020 16:58:46 +0200 Subject: [PATCH] two calc.py for combination --- sami/learn-python-the-hard-way/calc.py | 17 +++++++++++++++++ sami/learn-python-the-hard-way/calc2.py | 13 +++++++++++++ sami/learn-python-the-hard-way/output.txt | 0 3 files changed, 30 insertions(+) create mode 100644 sami/learn-python-the-hard-way/calc.py create mode 100644 sami/learn-python-the-hard-way/calc2.py create mode 100644 sami/learn-python-the-hard-way/output.txt diff --git a/sami/learn-python-the-hard-way/calc.py b/sami/learn-python-the-hard-way/calc.py new file mode 100644 index 0000000..51c8b18 --- /dev/null +++ b/sami/learn-python-the-hard-way/calc.py @@ -0,0 +1,17 @@ +# This function adds two numbers +def add(num1, num2): + return num1 + num2 +file = open("output.txt","a") +file.write(f's +# Take input from the user +select = int(input("Select operations form 1, 2, 3, 4 :")) + +number_1 = int(input("Enter first number: ")) +number_2 = int(input("Enter second number: ")) + + +print(number_1, "+", number_2, "=", + add(number_1, number_2)) + + + diff --git a/sami/learn-python-the-hard-way/calc2.py b/sami/learn-python-the-hard-way/calc2.py new file mode 100644 index 0000000..c9fe520 --- /dev/null +++ b/sami/learn-python-the-hard-way/calc2.py @@ -0,0 +1,13 @@ +def add(a,b): +# calculating the sum + sum=a+b + #opening the file in an append mode + file = open('output.txt',"a") + file.write(f'Sum of {a} and {b} is {sum}\n') + #at last i close the file + file.close() + + +#call the function +add(5,7) +add(2,6) diff --git a/sami/learn-python-the-hard-way/output.txt b/sami/learn-python-the-hard-way/output.txt new file mode 100644 index 0000000..e69de29