two calc.py for combination
This commit is contained in:
parent
78211363b9
commit
7f67a6bd5c
3 changed files with 30 additions and 0 deletions
17
sami/learn-python-the-hard-way/calc.py
Normal file
17
sami/learn-python-the-hard-way/calc.py
Normal file
|
@ -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))
|
||||
|
||||
|
||||
|
13
sami/learn-python-the-hard-way/calc2.py
Normal file
13
sami/learn-python-the-hard-way/calc2.py
Normal file
|
@ -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)
|
0
sami/learn-python-the-hard-way/output.txt
Normal file
0
sami/learn-python-the-hard-way/output.txt
Normal file
Loading…
Reference in a new issue