How do i get rid of parentheses and commas and ” when printing? /u/thewither2 Python Education

Every method i looked up doesn’t seem to work when trying to turn this output

(6, ‘+’, 8, ‘=’, 14) into just 6 + 8 = 14

because I need the second output to put into a list that I can then show, but it keeps holding onto every single part.

note that .replace doesn’t seem to *exist* when I try to use it.

edit: forgot the code

#set up the functions for the calculator def addition(a, b): return a + b def subtraction(x, y): return x - y def multiplication(x, y): return x * y def division(x, y): return x / y def asknum(): #Ints to prevent 2+2=22, since they would be plain text otherwise n1 = int(input("What's the first number?: ")) n2 = int(input("What's the second number?: ")) return n1, n2 outputs = [] loop = 0 while True: #ask questions before the code tries to run if loop >= 1: print("You may also ask for 'history' to see previous operations") choice = input("What is the operation? add/subtract/multiply/divide: ") #rolling through the options if choice == 'add': n1, n2 = asknum() out = (n1, str("+"), n2, str("="), addition(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == 'subtract': n1, n2 = asknum() out = (n1, "-", n2, "=", subtraction(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == 'multiply': n1, n2 = asknum() out = (n1, "*", n2, "=", multiplication(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == 'divide': n1, n2 = asknum() out = n1, "%", n2, "=", division(n1, n2) print(out) loop = loop + 1 outputs.append(out) elif choice == 'history': print(outputs) #failsafe in case input isn't good else: print("It seems like you didn't enter in an operation, please try again") continue 

submitted by /u/thewither2
[link] [comments]

​r/learnpython Every method i looked up doesn’t seem to work when trying to turn this output (6, ‘+’, 8, ‘=’, 14) into just 6 + 8 = 14 because I need the second output to put into a list that I can then show, but it keeps holding onto every single part. note that .replace doesn’t seem to *exist* when I try to use it. edit: forgot the code #set up the functions for the calculator def addition(a, b): return a + b def subtraction(x, y): return x – y def multiplication(x, y): return x * y def division(x, y): return x / y def asknum(): #Ints to prevent 2+2=22, since they would be plain text otherwise n1 = int(input(“What’s the first number?: “)) n2 = int(input(“What’s the second number?: “)) return n1, n2 outputs = [] loop = 0 while True: #ask questions before the code tries to run if loop >= 1: print(“You may also ask for ‘history’ to see previous operations”) choice = input(“What is the operation? add/subtract/multiply/divide: “) #rolling through the options if choice == ‘add’: n1, n2 = asknum() out = (n1, str(“+”), n2, str(“=”), addition(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == ‘subtract’: n1, n2 = asknum() out = (n1, “-“, n2, “=”, subtraction(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == ‘multiply’: n1, n2 = asknum() out = (n1, “*”, n2, “=”, multiplication(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == ‘divide’: n1, n2 = asknum() out = n1, “%”, n2, “=”, division(n1, n2) print(out) loop = loop + 1 outputs.append(out) elif choice == ‘history’: print(outputs) #failsafe in case input isn’t good else: print(“It seems like you didn’t enter in an operation, please try again”) continue submitted by /u/thewither2 [link] [comments] 

Every method i looked up doesn’t seem to work when trying to turn this output

(6, ‘+’, 8, ‘=’, 14) into just 6 + 8 = 14

because I need the second output to put into a list that I can then show, but it keeps holding onto every single part.

note that .replace doesn’t seem to *exist* when I try to use it.

edit: forgot the code

#set up the functions for the calculator def addition(a, b): return a + b def subtraction(x, y): return x - y def multiplication(x, y): return x * y def division(x, y): return x / y def asknum(): #Ints to prevent 2+2=22, since they would be plain text otherwise n1 = int(input("What's the first number?: ")) n2 = int(input("What's the second number?: ")) return n1, n2 outputs = [] loop = 0 while True: #ask questions before the code tries to run if loop >= 1: print("You may also ask for 'history' to see previous operations") choice = input("What is the operation? add/subtract/multiply/divide: ") #rolling through the options if choice == 'add': n1, n2 = asknum() out = (n1, str("+"), n2, str("="), addition(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == 'subtract': n1, n2 = asknum() out = (n1, "-", n2, "=", subtraction(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == 'multiply': n1, n2 = asknum() out = (n1, "*", n2, "=", multiplication(n1, n2)) print(out) loop = loop + 1 outputs.append(out) elif choice == 'divide': n1, n2 = asknum() out = n1, "%", n2, "=", division(n1, n2) print(out) loop = loop + 1 outputs.append(out) elif choice == 'history': print(outputs) #failsafe in case input isn't good else: print("It seems like you didn't enter in an operation, please try again") continue 

submitted by /u/thewither2
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *