0
can any one anyone send the code of simple calculator with beginner difficulty in python
pls
5 odpowiedzi
+ 2
no, i cant send a code, this is not a postal service for sending codes. but if you show me your genuine try i can definitely try to help you, well here's a hint to get you started.
write different functions to perform different tasks, like
def adds(x,y):
return x+y
this takes two numbers and return their sum, similarly write other functions for operations you want to perform, then write a function to take user input, use input() function.
then compare user input and call appropriate function.
+ 1
function=input("enter a function")
if function=="add":
x= int(input("no 1"))
y=int(input("no2"))
def print_sum(x,y):
print(x+y)
print("this is the answer")
print_sum(x,y)
if function=="product":
a= int(input("no 1"))
b=int(input("no2"))
def print_product(a,b):
print(b*a)
print("this is the answer")
print_product(a,b)
the addition function is working but the product is not working
+ 1
try to write the whole program in code playground, and define functions outside of if statement, and call the function inside of if block.
Here i can see you are calling print_sum() outside of if block which is causing problem, when you try to run with add the if statement executes and addition function gets executed, but when you do with product, the first if statement is never executed but print_sum() is still being called in next line and since its not defined this time, and thats why your program must be showing error.
Try like this:
def get_product(x,y):
return x+y
function = input("enter a function")
if function == "product":
x = input()
y = input()
print(product(x,y))
0
function=input("enter a function")
if function=="add":
x= int(input("no 1"))
y=int(input("no2"))
int z
z=x+y
print("this is the answer"+ z )
my code
0
pls help me in the code